I'm storing some custom data in HTML5 data attribute for Jquery processing. will the custom data attribute available in Older browsers?
我将一些自定义数据存储在HTML5数据属性中以进行Jquery处理。旧版浏览器中是否可以使用自定义数据属性?
4 个解决方案
#1
18
The HTML5 datalist
property is not available in older browsers (it can be polyfilled easily enough though). You can always use the standard getAttribute
method instead of course, and data-xxx
attributes on HTML elements are accepted by all browsers (as long as you're in HTML mode and not xHTML where they're invalid)
HTML5 datalist属性在旧版浏览器中不可用(尽管可以很容易地填充)。你总是可以使用标准的getAttribute方法,而且所有浏览器都接受HTML元素的data-xxx属性(只要你处于HTML模式而不是xHTML,它们是无效的)
But your question seems to be more specifically about jQuery than HTML5, and for that, the answer is Yes -- the jQuery .data()
method is available in all browsers supported by jQuery.
但是你的问题似乎更像是关于jQuery而不是HTML5,为此,答案是肯定的 - jQuery .data()方法在jQuery支持的所有浏览器中都可用。
#2
8
The attribute itself will work in all browsers. It's just an attribute after all. This would "work" in the sense that the attribute will exist in the DOM:
该属性本身适用于所有浏览器。毕竟这只是一个属性。在属性将存在于DOM中的意义上,这将“起作用”:
<div random-attribute="hello"></div> <!-- invalid, but "works" -->
<div data-random="hello"></div> <!-- valid (in browsers with HTML5 support) -->
The native dataset
property of elements will not work in older browsers, but getAttribute
will:
元素的原生数据集属性在旧版浏览器中不起作用,但getAttribute将:
var random = document.getElementById("x").dataset.random;
// or
var random = document.getElementById("x").getAttribute("data-random");
#4
0
Anything that supports HTML will be able to access a HTML data attribute. So processing it client side via JQUERY should be absolutely fine.
任何支持HTML的东西都能够访问HTML数据属性。因此,通过JQUERY处理客户端应该是绝对正常的。
In fact, i recently had to do this for a project at work and it worked a treat all the way down to ie7.
事实上,我最近不得不为工作中的项目做这件事,并且它一直在努力,直到ie7。
If you want to use the HTML data attributes for styling via CSS, then you would need browsers that support CSS3 selectos. Which is anything below IE9 and some older versions of firefox.
如果您想通过CSS使用HTML数据属性进行样式设置,那么您需要支持CSS3选择的浏览器。哪个是IE9以及一些旧版本的firefox。
This might be of interest to you:
您可能会对此感兴趣:
Do HTML5 custom data attributes “work” in IE 6?
IE5中的HTML5自定义数据属性是否“正常”?
#1
18
The HTML5 datalist
property is not available in older browsers (it can be polyfilled easily enough though). You can always use the standard getAttribute
method instead of course, and data-xxx
attributes on HTML elements are accepted by all browsers (as long as you're in HTML mode and not xHTML where they're invalid)
HTML5 datalist属性在旧版浏览器中不可用(尽管可以很容易地填充)。你总是可以使用标准的getAttribute方法,而且所有浏览器都接受HTML元素的data-xxx属性(只要你处于HTML模式而不是xHTML,它们是无效的)
But your question seems to be more specifically about jQuery than HTML5, and for that, the answer is Yes -- the jQuery .data()
method is available in all browsers supported by jQuery.
但是你的问题似乎更像是关于jQuery而不是HTML5,为此,答案是肯定的 - jQuery .data()方法在jQuery支持的所有浏览器中都可用。
#2
8
The attribute itself will work in all browsers. It's just an attribute after all. This would "work" in the sense that the attribute will exist in the DOM:
该属性本身适用于所有浏览器。毕竟这只是一个属性。在属性将存在于DOM中的意义上,这将“起作用”:
<div random-attribute="hello"></div> <!-- invalid, but "works" -->
<div data-random="hello"></div> <!-- valid (in browsers with HTML5 support) -->
The native dataset
property of elements will not work in older browsers, but getAttribute
will:
元素的原生数据集属性在旧版浏览器中不起作用,但getAttribute将:
var random = document.getElementById("x").dataset.random;
// or
var random = document.getElementById("x").getAttribute("data-random");
#3
#4
0
Anything that supports HTML will be able to access a HTML data attribute. So processing it client side via JQUERY should be absolutely fine.
任何支持HTML的东西都能够访问HTML数据属性。因此,通过JQUERY处理客户端应该是绝对正常的。
In fact, i recently had to do this for a project at work and it worked a treat all the way down to ie7.
事实上,我最近不得不为工作中的项目做这件事,并且它一直在努力,直到ie7。
If you want to use the HTML data attributes for styling via CSS, then you would need browsers that support CSS3 selectos. Which is anything below IE9 and some older versions of firefox.
如果您想通过CSS使用HTML数据属性进行样式设置,那么您需要支持CSS3选择的浏览器。哪个是IE9以及一些旧版本的firefox。
This might be of interest to you:
您可能会对此感兴趣:
Do HTML5 custom data attributes “work” in IE 6?
IE5中的HTML5自定义数据属性是否“正常”?