jQuery选择属性NAME以什么开头? [英] jQuery select when attribute NAME starting with?
本文介绍了jQuery选择属性NAME以什么开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除所有名称以data-val-range
开头的属性.
I want to remove all attributes with name starting data-val-range
.
即我要从以下元素中删除匹配的属性:
I.e. from the following element I wanna remove the matching attributes:
<input data-val-range-min="*" data-val-range-max="$" data-val-range="hallelujah"/>
这可能吗?
推荐答案
Using this answer, You can just iterate through the attributes, and remove them according to the name...
您的javascript应该类似于
Your javascript should be something like
$("input").each(function() {
var theElem=this;
$.each(this.attributes,function() {
if(this.specified) {
if(this.name.indexOf("data-val-range")>-1) {
console.log("removing ",this.name);
$(theElem).removeAttr(this.name);
}
}
})
});
这是一个jsfiddle https://jsfiddle.net/dkusds1s/
Here is a jsfiddle https://jsfiddle.net/dkusds1s/
这篇关于jQuery选择属性NAME以什么开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文