使用HTML5的“data-*”有什么问题吗?旧版浏览器的属性?
我想将一些自定义数据与一些 HTML 节点关联起来。我打算使用新的 HTML5 样式“data-*”属性。例如: ...
,然后我将选择这个 HTML 节点并通过读取值来显示/隐藏它等$(node).attr("data-typeid")
。
然而,该网页也需要与旧版浏览器兼容。我没有使用 data-* 属性作为特殊属性,但我想知道旧版浏览器是否会忽略、擦除或使该属性不可访问,因为它不是有效的 HTML4。
I want to associate some custom data with some HTML nodes. I was going to use the new HTML5 style 'data-*' attributes. e.g.: <tr class="foo" data-typeid="7">…
, and then I was going to select this HTML node and show/hide it etc. by reading the value with $(node).attr("data-typeid")
.
However this web page needs to work with older browsers aswell. I'm not using the data-* attribute as a special attribute, but I'd like to know if older browsers will ignore, wipe, or make inaccessible this attribute since it's not valid HTML4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实并非如此,当然它们在 HTML4 中并不是 100% 正确/有效的用法......但它们也不会引起问题,所以它们仍然是解决问题的好方法“我需要一个属性来解决这个问题”。
如果有帮助的话,我在支持 IE6 的同时使用了这些,并且到目前为止遇到了零问题,而且我也不记得有任何问题报告过。
There isn't really, they're not 100% correct/valid usage in HTML4 of course....but they don't cause problems either, so they're still a great way to solve the "I need an attribute for this" problem.
If it helps, I've used these while supporting IE6 and have had zero issues thus far, and I can't recall a single SO question reporting any either.
Internet Explorer 和 Microsoft 添加了多个不是有效 HTML4 的自定义属性。浏览器不会根据规范检查元素属性,如果您愿意,您可以命名属性
roryscoolinfo="hello"
(尽管您不应该这样做)。Dojo Toolkit 添加了自定义
dojo*
属性。现在使用
data-
和 HTML5 文档类型就很好了。Internet Explorer and Microsoft has added several custom attributes that are not valid HTML4. Browsers don't check the element attributes against a specification, you can name an attribute
roryscoolinfo="hello"
if you like (though you shouldn't).The Dojo Toolkit adds its custom
dojo*
attributes.It's fine to use
data-
today, with a HTML5 doctype.