[英]Using non W3C valid attributes on HTML elements
What is your opinion about using non valid attributes on html elements for easier jQuery selectors etc ? 您对在html元素上使用无效属性以简化jQuery选择器等有何看法?
Eg. 例如。
<div name="myDiv"></div>
According to Visual Studio the name attribute is not valid for a div element. 根据Visual Studio,名称属性对于div元素无效。
I would recommend using "dummy" classes (and the jQuery class selector) to disambiguate naming of html elements. 我建议使用“虚拟”类(和jQuery类选择器)来消除html元素的命名歧义。 100% compliant approach.
100%兼容的方法。
If you absolutely must , use the data
pseudo-namespace; 如果绝对必须 ,请使用
data
伪命名空间; such as data-id
or data-name
. 例如
data-id
或data-name
。
Edit: Using the data
pseudo-namespace is far better than perverting the usage of an existing attribute like class
or id
. 编辑:使用
data
伪命名空间远胜于扭曲class
或id
class
的现有属性的使用。
如果您仍然想保持与w3c的兼容性,则w3c允许title
属性提供额外的信息,您可以使用它们来代替添加新的非标准属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.