那些棉胎不能要:jquery如何遍历已定义的属性

来源:百度文库 编辑:九乡新闻网 时间:2024/05/01 14:04:01
HTML code

JScript code
var el = document.getElementById("el"), atts = el.attributes, len = atts.length, att, i = 0 ;for(; i < len ; i++){att = atts[i];if(att.specified){alert(att.name + " , " + att.value)}}
Jquery code:
$("*").each(function(){
              var attrs= $(this).get(0).attributes;
              for(i=0; i <attrs.length ; i++){
                      att = attrs[i];
                      if(att.specified &&att.name.toLowerCase().indexOf("on")!=-1)
                      {
                           alert(att.name);
                           $(this).get(0).removeAttribute(att.name);                      
                      }
                    }
  })