在HTML5中使用自定义元素是不好的做法吗? [英] Is it bad practice to use custom elements in HTML5?

查看:98
本文介绍了在HTML5中使用自定义元素是不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 document.getElementByTagName 之类的东西,你几乎可以创建自己的元素。

Using stuff like document.getElementByTagName, you can practically create your own elements.

<arial>Hello</arial>

然后在JS ..

var a = document.getElementsByTagName("arial");

for(i = 0; i < a.length; ++i)
     a[i].style.fontFamily = "Arial"

我们有一个自定义元素,很容易。

And we have a custom element, easy peasy.

我的问题归结为,这是不好的做法吗?是否有一些我不注意的缺点?

My question comes down to, is this bad practice? Is there some drawback I'm not noticing?

推荐答案

W3C说你不应该。这是不好的做法。


作者不得使用本规范或其他适用的
规范不允许
的元素,属性或属性值,因为这样做会使
语言变得更加困难将来需要延期。

Authors must not use elements, attributes, or attribute values that are not permitted by this specification or other applicable specifications, as doing so makes it significantly harder for the language to be extended in the future.

此外,HTML5 不是 XML。您应该只使用官方规范中列出的元素。

Furthermore, HTML5 is not XML. You should only use the elements outlined in the official spec.

这篇关于在HTML5中使用自定义元素是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆