IE5中的HTML5自定义数据属性是否“正常”? [英] Do HTML5 custom data attributes “work” in IE 6?

查看:139
本文介绍了IE5中的HTML5自定义数据属性是否“正常”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自定义数据属性: http:// dev.w3.org/html5/spec/Overview.html#embedding-custom-non-visible-data

当我说工作时,我这意味着,如果我有这样的HTML:

When I say "work", I mean, if I’ve got HTML like this:

<div id="geoff" data-geoff="geoff de geoff">

会包含以下JavaScript代码:

will the following JavaScript:

var geoff = document.getElementById('geoff');
alert(geoff.dataGeoff);

会在IE 6中产生一个带有geoff de geoff的警告吗?

produce, in IE 6, an alert with "geoff de geoff" in it?

推荐答案

您可以使用 getAttribute 检索自定义(或您自己的)属性的值。按照你的例子

You can retrieve values of custom (or your own) attributes using getAttribute. Following your example with

<div id="geoff" data-geoff="geoff de geoff">

我可以得到 data-geoff 使用

var geoff = document.getElementById("geoff");
alert(geoff.getAttribute("data-geoff"));

请参阅 MSDN 。虽然在那里提到你需要IE7来实现这个功能,但我前一段时间用IE6对它进行了测试,它运行正常(即使在怪癖模式下)。

See MSDN. And although it is mentioned there that you need IE7 to get this to work, I tested this a while ago with IE6 and it functioned correctly (even in quirks mode).

但这当然与HTML5特定的属性无关。

But this has nothing to do with HTML5-specific attributes, of course.

这篇关于IE5中的HTML5自定义数据属性是否“正常”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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