dom属性相关方法:
1.) each ():循环⽅法。使用方法:
$(“li”).each(function (index,item) {
console.log(index,item);
//index代表每个li元素的下标。item表示每个li元素
});
2.)attr()方法: 设置或者获取元素的属性。使用方法:
var title = $("em").attr("title");
//设置或者获取em元素的title属性。
$("div").text(title)
3.)removeAttr()方法: 删除元素属性。使用方法:
$("input").removeAttr("data");
//删除input元素上的data属性
4.)prop()方法:设置或者获取元素的属性。使用方法:
$("input").prop("checked",true);
5.)removeProp()方法:
$("input").removeProp("checked");
注意:具有 true 和 false 两个属性值的属性,如 checked, selected 或者 disabled 使⽤prop()方法,
其他的使⽤ attr()方法。