如果我不给数据属性加上“ data-”作为前缀,会发生什么? [英] What happens if I don't preface data attributes with "data-"?

查看:86
本文介绍了如果我不给数据属性加上“ data-”作为前缀,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常最终将数据存储在DOM元素中,并大量使用自定义数据属性和JQuery。我知道HTML5规范说数据属性应该有 data-前缀,但是据我所知,随意命名我的属性没有什么害处。

I frequently end up storing data in DOM elements and make heavy use of custom data attributes and JQuery. I know the HTML5 spec says data attributes should have the data- prefix, but as far as I can tell there's no harm in naming my attributes whatever I want.

问题?

推荐答案

唯一的问题是验证。非标准元素属性不是有效的HTML5。因此,它们中没有危害,但是在任何规范之外进行操作的危险在于,将来或特定的用户代理可能不支持该规范。您还冒着将来该规范将 include 包含非标准属性的风险,但这将完全意味着您的预期之外的含义。更糟糕的情况是,当实现规范的新功能时,您必须去更新页面。

The only problem is in validation. Non-standard element attributes are not valid HTML5. So, there is no harm in them, but the danger of operating outside of any spec is that it may not be supported in the future or by a specific user-agent. You also run the risk that in the future, the spec will include your non-standard attribute, but it will mean something else entirely than what you intended. Worse case scenario, you have to go update the page when a new feature of the spec is implemented.

对于元素属性,应该 可在所有浏览器中使用。

In the case of element attributes, it should work in all browsers.

查看 http://msdn.microsoft.com/zh-cn/library/ms536429%28VS.85%29.aspx ,以获取有关此主题的信息,因为它与Internet相关资源管理器。

Check out http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx for info on this subject as it pertains to Internet Explorer.

这篇关于如果我不给数据属性加上“ data-”作为前缀,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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