Javascript element.attributes是否包含自定义数据属性?
我想知道属性数组中存储了哪些元素是否存在浏览器一致性Javascript element.attributes是否包含自定义数据属性?,javascript,jquery,attributes,custom-data-attribute,Javascript,Jquery,Attributes,Custom Data Attribute,我想知道属性数组中存储了哪些元素是否存在浏览器一致性 example of looping through all data attributes; <input type="text" id="x" data-a="valuea", data-b="valueb" /> $.each($('#x').data(), function(key, value) { console.log('key is', key); console.log('value is', val
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
是否通过“$('#elm')[0].attributes”找到所有“数据xxx”属性
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
例如,“属性”集合是否包含以下所有数据属性:
<input type="submit" value="Go" data-validation="foo" data-widgetId="bar">
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
我需要的是一种使用jQuery将所有相关属性从输入[type=submit]移动到按钮元素的方法。关于.attributes的浏览器支持信息
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
var attrs=$(“输入[type=submit]”[0]);
对于(var i=0;i浏览器支持有关.attributes的信息
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
var attrs=$(“输入[type=submit]”[0]);
对于(var i=0;i目前没有多少浏览器对数据集
属性具有本机支持,这是访问数据-*
属性的官方标准方式。这将随着时间的推移而改进,但目前还不足以支持使用(有关更多信息,请参阅)
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
但是,正如您所知,所有浏览器都可以将数据-*
作为普通属性来支持。但是在缺少数据集
属性的情况下,无法轻松获取所有数据-*
属性
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
幸运的是,有一个JQuery插件提供了此功能。有关更多信息,请参见此处:目前没有多少浏览器对数据集
属性提供本机支持,这是访问数据-*
属性的官方标准方法。这将随着时间的推移而改进,但目前还不足以支持使用(有关更多信息,请参阅)
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
但是,正如您所知,所有浏览器都可以将数据-*
作为普通属性来支持。但是在缺少数据集
属性的情况下,无法轻松获取所有数据-*
属性
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
幸运的是,有一个JQuery插件提供了此功能。有关更多信息,请参见此处:我认为数据属性在所有浏览器中都存在,即使在非HTML 5浏览器中它们被忽略
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
这里有人设法从IE6中的一个元素中读取它们
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
@编辑答案
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
刚刚发现jquery data()可以与html5和非html5浏览器一起使用
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
循环遍历所有数据属性的示例;
$.each($('#x').data(),函数(键,值){
console.log('key is',key);
console.log('value is',value);
});
印刷品
钥匙是一把钥匙
价值就是价值
关键是b
价值就是价值B
我认为数据属性在所有浏览器中都存在,即使在非HTML 5浏览器中被忽略
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
这里有人设法从IE6中的一个元素中读取它们
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
@编辑答案
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
刚刚发现jquery data()可以与html5和非html5浏览器一起使用
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
example of looping through all data attributes;
<input type="text" id="x" data-a="valuea", data-b="valueb" />
$.each($('#x').data(), function(key, value) {
console.log('key is', key);
console.log('value is', value);
});
prints
key is a
value is valuea
key is b
value is valueb
循环遍历所有数据属性的示例;
$.each($('#x').data(),函数(键,值){
console.log('key is',key);
console.log('value is',value);
});
印刷品
钥匙是一把钥匙
价值就是价值
关键是b
价值就是价值B
必须阅读以下内容:Yeah.attr()非常棒,但它没有给我一个包含键/值对的对象来循环。我更新您的问题。请参阅编辑部分。如果这不是您想要的内容,请删除。这不是我的意思,所以是的,我删除了它:)您有一些检查答案必须阅读以下内容:Yeah.attr()但是它没有给我一个包含键/值对的对象来循环。我更新了你的问题。请参见编辑部分。如果它不是你想要的,请删除。这不是我的意思,所以是的,我删除了它:)你有一些答案需要检查。我不知道这是如何回答我的问题的。是的,我可以在我能想象的每个浏览器中这样测试它,但我问这个问题是为了看看是否有人已经这样做了。但无论如何,谢谢。我不知道这如何回答我的问题。是的,我可以在我能想象的每个浏览器中这样测试它,但我问了这个问题我想看看是否有人已经这样做了。不过还是要谢谢你。