什么是使用数据 - 而不是X-preFIX自定义属性的优势是什么?自定义、而不是、属性、优势

2023-09-13 02:54:45 作者:今夜星满天

AngularJS文档说 可选的指令可以prefixed以x-或DATA-使它HTML验证标准。

AngularJS documentation says Optionally the directive can be prefixed with x-, or data- to make it HTML validator compliant..

标记示例:

没有preFIX:&LT;输入NG模型=名&GT; 数据 - &LT;输入数据-NG-模式=名&GT; X - :&LT;输入x-NG-模式=名&GT; no prefix: <input ng-model="name"> data- : <input data-ng-model="name"> x- : <input x-ng-model="name">

的 X - preFIX快于数据类型 - ,但教程我见过使用,也没有preFIX或数据 - ,所以我的问题是:是否有我可能要使用的任何原因数据 - ,而不是 X - ?

The x- prefix is faster to type than data-, but the tutorials I have seen used either no prefix or data-, so my question is: are there any reasons I might want to use data- rather than x-?

推荐答案

使用数据的优势 - preFIX而非点¯x - preFIX是数据 - prefixes保证,因为他们喜欢保持可用作者,而一个 X - preFIX有一天可能会被用于特定浏览器的目的,可能与你相互矛盾的。需要注意的是 X - 没有按照符合HTML5

The advantage of using a data- prefix rather than an x- prefix is that data- prefixes are guaranteed to remain available to authors as they like, whereas an x- prefix might one day be used for a browser-specific purpose, possibly conflicting with yours. Note that x- are not conforming according to HTML5.