jQuery选择属性NAME以什么开头?

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/