我们是否需要注册自定义标签? [英] Do we need to register Custom Tag?
问题描述
我一直在阅读有关HTML5自定义元素的这篇文章。
它说我需要在使用它之前注册元素的名称,例如:
var XFoo = document.registerElement('x-foo');
document.body.appendChild(new XFoo());
然后我可以开始正常使用它:
< X-FOO> ...< / X-FOO>
但我只是在未经Chrome,Firefox和IE11注册的情况下尝试使用它。所有似乎都呈现得很好,即使CSS选择器 x-foo
也可以。
我猜我们不再需要注册,因为大多数浏览器都支持它?
谢谢
简短回答:否。
作为一种好习惯,总是定义一些不是官方的东西。仅仅因为它适用于所有/大多数浏览器并不能使其正确。这与使用尚未定义的变量相似,然后编译器自动定义它。当然,它可以工作,但这并不能说明问题。
I have been reading this article about HTML5 Custom Element.
It said I need to register the element's name before using it like:
var XFoo = document.registerElement('x-foo');
document.body.appendChild(new XFoo());
Then I can start using it normally:
<x-foo>...</x-foo>
But I just tried using it without registering in Chrome, Firefox, and IE11. All seems to render just fine, even CSS selector for x-foo
also works.
I'm guessing that we no longer need to register since most browsers have supported it?
Thanks
Short answer: No.
As a good practice, always define things that are not official. Just because it works by all/most browsers does not make it correct. That would be similar to using a variable which is yet to be defined, and then the compiler automatically defining it. Sure, it works, but that does not make it right
这篇关于我们是否需要注册自定义标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!