HTML数据属性IE6支持 [英] HTML data attribute IE6 support

查看:74
本文介绍了HTML数据属性IE6支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML的数据属性可以在IE6中使用吗?

Does HTML's data attribute work in IE6?

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

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">.

您会看到有2个数据属性(价格和代码).我可以使用.data()方法使用jQuery来获得此功能,而这一切似乎都可以在IE7/8/9中使用.这在IE6中有效吗?我没有IE6的副本可以对此进行测试.

As you can see there are 2 data attributes (price and code). I can get this with jQuery using the .data() method and it all seems to work in IE7/8/9. Does this work in 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.

在HTML5标准中正式使用了data-作为前缀,但是浏览器一直都支持它,甚至根本不需要data-前缀.

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-前缀,因为它现在已成为标准的一部分,因此将来的浏览器可能对此更加挑剔,并且还因为已将新的dataset属性添加到HTML5 DOM中同时支持它的规范.

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.

很明显,您不能使用dataset属性,因为很少有浏览器支持它(甚至不支持较新的浏览器,更不用说较旧的浏览器了),但是您当然可以始终使用旧的getAttribute()方法(是jQuery的功能.)

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).

要了解有关浏览器对新属性的支持,我建议使用CanIUse.com网站.例如,这是他们关于data-属性的页面: http://caniuse.com/#search=dataset .它们具有用于各种功能的完整浏览器支持表.

To find out about browser support for new properties, I recommend the CanIUse.com site. For example, here is their page about data- attributes: http://caniuse.com/#search=dataset. They have full browser support tables for a wide range of features.

希望有帮助.

这篇关于HTML数据属性IE6支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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