使用jquery删除多个html5数据属性

所以jquery api说如下:

Removing data from jQuery’s internal .data() cache does not effect any HTML5 data- attributes in a document; use .removeAttr() to remove those.

删除单个数据属性没有问题.

<a title="title" data-loremIpsum="Ipsum" data-loremDolor="Dolor"></a>
$('a').removeAttr('data-loremipsum');

问题是,如何删除多个数据属性

更多细节:

>出发点是我有多个(让我们说.. 60)
不同的数据属性,我想删除所有这些.
>首选方法是仅定位包含单词lorem的数据属性.在这种情况下,lorem始终是第一个词. (如果算上数据,则为秒数)
>另外,我想保持所有其他属性不变

解决方法

// Fetch an array of all the data
var data = $("a").data(),i;
// Fetch all the key-names
var keys = $.map(data,function(value,key) { return key; });
// Loop through the keys,remove the attribute if the key contains "lorem".
for(i = 0; i < keys.length; i++) {
    if (keys[i].indexOf('lorem') != -1) {
        $("a").removeAttr("data-" + keys[i]);
    }
}

小提琴:http://jsfiddle.net/Gpqh5/

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...