手册
目录
收藏123
分享
阅读9498
更新时间2022-04-11
如有疑问欢迎到这些地方交流,欢迎加入JSLite.io组织团伙共同开发!
获取对象集合中每一个元素的属性值。
$("#box").pluck("nodeName") //⇒ ["DIV"]
$("#box").pluck("nextElementSibling") //⇒ <div class="boxs">1234567890</div>
$("#box").pluck("children") //⇒ [HTMLCollection[4]]
读取或设置dom的属性。
$(".button").attr({"class":"","style":"background:red"}) //⇒ self 设置红色清空class
$(".button").attr("class","name") //⇒ self 设置class替换之前的
$(".button").attr("class") //⇒ string 获取class属性值
移动当前对象集合中所有元素的指定属性。
$("#box").removeAttr("class") //⇒ self 移除class
读取或设置dom的属性。它在读取属性值的情况下优先于 attr,因为这些属性值会因为用户的交互发生改变,如
checked和selected。
<input class="taiyang" id="check1" type="checkbox" checked="checked">
<input class="yaotaiyang" id="check2" type="checkbox">
$("#check1").attr("checked"); //=> "checked"
$("#check1").prop("checked"); //=> "true"
$("#check2").attr("checked"); //=> "false"
$("#check2").prop("checked"); //=> "false"
$("input[type="checkbox"]").prop("type",function(index,oldvalue){
console.log(index+"|"+oldvalue);
});
//=> 0|checkbox
//=> 1|checkbox
$("input[type="checkbox"]").prop("className",function(index,oldvalue){
console.log(index+"|"+oldvalue);
});
//=> 0|taiyang
//=> 1|yaotaiyang
为集合中匹配的元素删除一个属性(property)。
removeProp()方法用来删除由.prop()方法设置的属性集。
注意: 不要使用此方法来删除原生的属性( property ),比如checked, disabled, 或者 selected。这将完全移除该属性,一旦移除,不能再次被添加到元素上。使用.prop()来设置这些属性设置为false代替。
<p id="n2" class="demo test" data-key="UUID" data_value="1235456465">CodePlayer</p>
var $n2 = $("#n2");
$n2.prop("prop_a", "CodePlayer");
$n2.prop("prop_b", { name: "CodePlayer", age: 20 } );
console.log($n2.prop("prop_a")) //⇒ CodePlayer
console.log($n2.prop("prop_b")) //⇒ Object {name: "CodePlayer", age: 20}
$n2.removeProp("data-key");
$n2.prop("data-key") //⇒ undefined
$n2.attr("data-key") //⇒ "UUID"
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
共5课时
17.3万人学习
共49课时
77.3万人学习
共29课时
61.9万人学习
共25课时
39.5万人学习
共43课时
71.2万人学习
共25课时
61.8万人学习
共22课时
23.1万人学习
共28课时
34.1万人学习
共89课时
125.7万人学习