如何AngularJS使用自定义的HTML5元素标记和属性脱身?

问题描述:

大多数浏览器似乎允许你创建你喜欢的任何元素标签,并添加你喜欢的任何元素的属性名称。例如:

Most browsers seem to allow you to create any element tag you like, and add any attribute name you like to elements. For example:

<!DOCTYPE html>
<html>
<body>
<div my-attribute="has no data- prefix, but seems to behave like an attribute should">
    <br/>
    <hello-world style="display:block;background:#eee">Hello Everybody</hello-world>
    <goodby-world style="background:#faa">Default display is inline</goodbye-world>
</div>
</body>
</html>

以上显示细腻。它看起来像undefined元素表现pretty很像跨度。
它也像AngularJS利用自定义标签和放大器;属性颇多 - 它pretty很大程度上取决于它

The above displays fine. It looks like undefined elements behave pretty much like spans. It also looks like AngularJS takes advantage of custom tags & attributes quite a lot - it pretty much depends on it.

不过,据我了解,做那种事情是一个没有没有,除了在定制HTML5的情况下,属性与数据 - preFIX。

But, as far as I understood, doing that sort of thing was a no-no, except in the case of custom html5 attributes with the "data-" prefix.

所以,我的问题是:它使不再忌讳了自己的自定义元素标记和/或属性名称?或者换一种说法,那AngularJS依靠不规范的怪癖是不是真的HTML5规范的一部分,但只是碰巧反正工作?难道有人在​​谷歌发现HTML5规范的久违的秘密章节?还是我完全误解的东西?

So, my question is: Is it no longer taboo to make up your own custom element tags and/or attribute names? Or put another way, does AngularJS rely on non-standard quirks that are not really part of the HTML5 spec, but just happen to work anyway? Did somebody at google discover a long-lost secret chapter of the html5 spec? Or am I totally misunderstanding something?

这不会验证,但它将呈现。

It won't validate but it will render.

HTML5的设计是非常宽容的(与XHTML)。这部分是让老HTML5的浏览器可以允许新的元素(以及错误格式的HTML)这是版本不不破的页面还没有支持。

HTML5 is designed to be very forgiving (contrary to XHTML). This is in part so that "older" HTML5 browsers can allow new elements (as well as badly formatted HTML) which that version doesn't support yet without breaking the page.

当然,这可以被剥削,介绍自定义标签。

This can of course be "exploited" to introduce custom tags.

话虽这么说 - 你也可以做到这一点与HTML4

That being said - you can also do this with HTML4.

正如评论所说:你也有能力为preFIX在一个普通的标签的任何属性与数据 - ,它会验证

As mentioned in comments: you also have the ability to prefix any attributes in an ordinary tag with data- and it will validate.