Is there any problem with using HTML5's “data-*” attributes for older browsers?

牧云@^-^@ 提交于 2019-11-26 11:19:44

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3957867/is-there-any-problem-with-using-html5s-data-attributes-for-older-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!