extends 属性的用例看起来非常简单(http://www.x-tags.org/docs#custom-tag-registration-extends),但是使用以下标记定义进行测试:
(function () {
xtag.register('dk-foo', {
extends: 'b',
lifecycle: {
created: function () {
this.innerHTML = '*FOO*';
}
}
});
}());
和标记:
<dk-foo>Hello BAR</dk-foo>
似乎没有任何效果(即文本不是粗体),更糟糕的是,它在 Chrome 上崩溃了。
我已经测试了 IE11、FF28、Safari 5.1.17 和 Chrome 33/35。除了 Chrome,每个浏览器都在 lifecycle.created
中运行代码(即将文本更改为 *FOO*
)。如果我删除 extends
属性,它也会在 Chrome 上运行。
除了上面的文档,我没能找到更多关于 extends
的文档,也找不到任何使用它的标签(虽然我当然没有看过所有的文档...) .
我是否只是错误地使用了 extends
属性......?
最佳答案
根据 this comment :
When you extend an element, you need to use the is="" syntax in your markup: . The is="" attribute is part of the standard, it's the only way to create custom elements from native elements.
我试过了,您实际上需要 is=
和 extends
。我不喜欢 is=
所以我实际上只是在创建一个内部元素,在你的例子中,一个内部 b
。
关于javascript - X-Tag 中是否弃用了 `extends` 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21970310/