引自jquery官网:
.removeAttr( attributeName )
attributeNameAn attribute to remove; as of version 1.7, it can be a space-separated list of attributes.
jquery同时删除元素标签的多个属性,必须使用1.7或以上的版本才能实现,两个要删除的属性中间必须用空格隔开(同removeClass()删除多个class值格式写法一样)
效果:点击按钮,去除div标签 class、title属性
注意:引用的是v1.7的jquery库
*{margin:0;padding:0;}
ul li{ list-style:none;}
img {border:0 none;}
input[type='button']{width:100px; height:38px;display:block;position:fixed;right:20%; top:50px;}
p{color:#f00;}
.c1{ border:1px red solid;}
$(function(){
$("input[type='button']").focus().click(function(){
$('div').removeAttr("title class");
})
})
提示:你可以先修改部分代码再运行。
另外一次性给元素添加多个属性,同css()语法、用法保持一致,方法如下:
$(obj).attr({
key1:value1,
key2:value2
})