简体   繁体   English

HTML数据属性IE6支持

[英]HTML data attribute IE6 support

Does HTML's data attribute work in IE6? HTML的数据属性是否适用于IE6?

I'm using the attribute like this <img id="charm_1" data-code='sdfsdfsdfsdf' data-price='100' class='addition_image' src="img/misc/donut.png" width="55" height="55" alt="Donut"> . 我正在使用这样的属性<img id="charm_1" data-code='sdfsdfsdfsdf' data-price='100' class='addition_image' src="img/misc/donut.png" width="55" height="55" alt="Donut">

As you can see there are 2 data attributes (price and code). 如您所见,有2个数据属性(价格和代码)。 I can get this with jQuery using the .data() method and it all seems to work in IE7/8/9. 我可以使用.data()方法使用jQuery来实现这一点,它似乎都适用于IE7 / 8/9。 Does this work in IE6? 这在IE6中有效吗? I don't have a copy of IE6 to test this. 我没有IE6的副本来测试这个。

IE6 -- and indeed all other browsers on the market -- have always been perfectly happy for you to define your own custom attributes on an element. IE6 - 以及市场上的所有其他浏览器 - 总是非常高兴您在元素上定义自己的自定义属性。

The use of data- as a prefix was formalised in the HTML5 standard, but browsers have always supported it, and don't even really require the data- prefix. 使用data-作为前缀在HTML5标准中形式化,但浏览器一直支持它,甚至不需要data-前缀。

The data- prefix is recommended because it is now part of the standard, so there's a chance that a future browser may be more picky about it, and also because of the new dataset property that was added to HTML5 DOM specification at the same time to support it. 建议使用data-前缀,因为它现在是标准的一部分,因此未来的浏览器可能会对它更加挑剔,同时也因为同时添加到HTML5 DOM规范的新dataset属性支持它。

Obviously you can't use the dataset property, as very few browsers support it (not even newer ones, let alone older ones), but you can of course always use the good old getAttribute() method instead (which is what jQuery does). 显然你不能使用dataset属性,因为很少有浏览器支持它(不是更新的,更不用说旧的了),但你当然总是可以使用旧的getAttribute()方法(这是jQuery所做的) 。

To find out about browser support for new properties, I recommend the CanIUse.com site. 要了解有关新属性的浏览器支持,我建议使用CanIUse.com网站。 For example, here is their page about data- attributes: http://caniuse.com/#search=dataset . 例如,这是他们关于data-属性的页面: http//caniuse.com/#search=dataset They have full browser support tables for a wide range of features. 它们具有完整的浏览器支持表,可用于各种功能。

Hope that helps. 希望有所帮助。

您可以使用IETester在不同版本的IE上测试您的网站,是的,它们适用于IE6,IE支持IE4的getAttribute() ,这是jQuery在内部用于data()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM