HTML5 自定义数据属性在 IE 6 中“有效"吗? [英] Do HTML5 custom data attributes “work” in IE 6?

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

问题描述

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

当我说工作"时,我的意思是,如果我有这样的 HTML:

将使用以下 JavaScript:

var geoff = document.getElementById('geoff');警报(geoff.dataGeoff);

在 IE 6 中生成带有geoff de geoff"的警报?

解决方案

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

我可以使用

获取data-geoff的值

var geoff = document.getElementById("geoff");警报(geoff.getAttribute(数据-geoff"));

请参阅 MSDN.虽然那里提到你需要 IE7 才能让它工作,但我不久前用 IE6 测试过它并且它运行正常(即使在怪癖模式下).

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

Custom data attributes: http://dev.w3.org/html5/spec/Overview.html#embedding-custom-non-visible-data

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

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

will the following JavaScript:

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

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

解决方案

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

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

I can get the value of data-geoff using

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

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

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

这篇关于HTML5 自定义数据属性在 IE 6 中“有效"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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