编程语言
首页 > 编程语言> > javascript – AngularJS应用程序应该符合HTML5标准吗?

javascript – AngularJS应用程序应该符合HTML5标准吗?

作者:互联网

我已经熟悉了AngularJS,并且我注意到可以通过在指令前添加数据来使您的模板代码符合HTML5标准. (例如,data-ng-repeat =“…”而不是ng-repeat =“…”.)

我的第一直觉是为我的所有指令添加前缀,但我一直在想:这是否有令人信服的理由?是否有任何确认的浏览器无效HTML属性出现问题?在一段时间之后,在所有内容之前输入数据变得相当繁琐,并且它使得HTML模板的可读性低得多.

解决方法:

Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK (“), U+0027 APOSTROPHE (‘), “>” (U+003E), “/” (U+002F), and “=” (U+003D) characters, the control characters, and any characters that are not defined by Unicode. In the HTML syntax, attribute names, even those for foreign elements, may be written with any mix of lower- and uppercase letters that are an ASCII case-insensitive match for the attribute’s name.

http://www.w3.org/TR/html/syntax.html#attributes-0

Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

http://www.w3.org/TR/html5/dom.html#custom-data-attribute

经过更多的挖掘,我找到了data- *属性的部分.但是,它并没有真正说它是“必须”.它更像是“我们建议使用它”.

Afaik,浏览器无法识别的属性将被忽略,但仍可通过DOM对象的getAttribute方法和attributes属性访问. data- *通常是语义和方便的首选,特别是在使用dataset时.

在类似的说明中,较旧版本的角度甚至recommends attribute name restrict指令作为元素名称的替代限制了IE8的兼容性.指令通常具有自定义名称,这应该是自定义属性名称正常的指示符.

标签:javascript,angularjs,html5,standards,web-standards
来源: https://codeday.me/bug/20190702/1358195.html