如何属性prefixes" X-"和"数据 - "在AngularJS使用 [英] How are the attribute prefixes "x-" and "data-" used in AngularJS

查看:91
本文介绍了如何属性prefixes" X-"和"数据 - "在AngularJS使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的角,并试图了解什么是X-和数据 - prefixes的意思。在指令文件( http://docs.angularjs.org/guide/directive ),它说,这些prefixes将使指令HTML验证标准。这到底是什么意思?

I'm new to Angular and trying to understand what the "x-" and "data-" prefixes mean. In the directives documentation (http://docs.angularjs.org/guide/directive) it says that these prefixes will make the directive "HTML validator compliant". What exactly does this mean?

推荐答案

HTML5规范允许任意的属性,只要他们与数据 - 像这样pfixed $ P $:

The HTML5 spec allows for arbitrary attributes as long as they're prefixed with data- like so:

<div data-myattribute=""></div>

而这将是无效的HTML5:

Whereas this would be invalid HTML5:

<div myattrbute=""></div>

<一个href=\"http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#embedding-custom-non-visible-data-with-the-data-attributes\">For在数据 - 属性的更多信息,看看这里

至于X-属性,我觉得你的意思是X的属性和元素,这是特定于XHTML验证...

As for "x-" attributes, I think you mean "x:" attributes and elements, which are specific to XHTML validation...

要扩大这一点,如果你要(因为某些原因)使用XHTML,您可以定义与命名空间自定义属性,像这样(我只是总结的要点这里):

To expand on this, if you were to (for some reason) be using XHTML, you can define custom attributes with namespacing like so (and I'm just summarizing the gist here):

<html xmlns:x="http://sample.com/mynamespace">
<body>
   <div x:whatever=""></div>
   <x:mytag></x:mytag>
</body>
</html>

其中的xmlns URL是真的只是像元素之间prevent冲突。此外,可以提供自定义元素和属性的DTD用于验证作为你的DOCTYPE声明的一部分。

where the URL in xmlns is really just to prevent conflicts between like elements. Also, a DTD for the custom elements and attributes could be provided for validation purposes as a part of your DOCTYPE declaration.

*在浏览器中的行为会与此的xmlns方法来改变。

*behavior in browsers is going to vary with this xmlns approach.

综上所述,虽然:大多数浏览器在过去的三年中释放或IE8 +你不会担心任何这些东西只有在非常特殊的情况下,你真的无所谓了。

In summary, though: With most browsers released in the last three years, or IE8+ you're not going to have to worry about any of these things. Only in very specific situations will you really care.

这篇关于如何属性prefixes&QUOT; X-&QUOT;和&QUOT;数据 - &QUOT;在AngularJS使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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