jQuery学习笔记--属性prop() removeProp()
prop(name|properties|key,value|fn)
---------------------------------
name 属性名称
$("input[type='checkbox']").prop("checked");
说明:选择type为checkbox的input元素,设置其为选中状态
properties 作为属性的“名/值对”对象
$("input[type='checkbox']").prop({disabled: true});
说明:选择type为checkbox的input元素,设置为禁用状态
key,value 属性名称,属性值
$("input[type='checkbox']").prop("disabled", false);
$("input[type='checkbox']").prop("checked", true);
说明:选择type为checkbox的input元素,设置为选中及禁用状态
key,function(index, attr) 属性名称,返回属性值的函数,第一个参数为当前元素的索引值,第二个参数为原先的属性值。
$("input[type='checkbox']").prop("checked", function( i, val ) {
return !val;
});
说明:通过函数来设置所有页面上的复选框被选中。
=================================================================================
removeProp(name)
----------------------------------
说明:用来删除由.prop()方法设置的属性集
示例:
var $para = $("p");
$para.prop("luggageCode", 1234);
$para.append("The secret luggage code is: ", String($para.prop("luggageCode")), ". ");
$para.removeProp("luggageCode");
$para.append("Now the secret luggage code is: ", String($para.prop("luggageCode")), ". ");
解释:设置一个段落数字属性,然后将其删除。

浙公网安备 33010602011771号