jquery笔记:attr, removeAttr,prop

来源:互联网 发布:win10有线网络显示红叉 编辑:程序博客网 时间:2024/05/15 19:23

attr(name|properties|key,value|fn)

设置或返回被选元素的属性值。

nameStringV1.0

属性名称

properties MapV1.0

作为属性的“名/值对”对象

key,value String,ObjectV1.0

属性名称,属性值

key,function(index, attr) String,FunctionV1.1

1:属性名称。

2:返回属性值的函数,第一个参数为当前元素的索引值,第二个参数为原先的属性值。

示例:
$("img").attr({ src: "test.jpg", alt: "Test Image" });
$("img").attr("src","test.jpg");


removeAttr(name)

从每一个匹配的元素中删除一个属性


prop(name|properties|key,value|fn)

name StringV1.6

属性名称

properties MapV1.6

作为属性的“名/值对”对象

key,value String,ObjectV1.6

属性名称,属性值

key,function(index, attr) String,FunctionV1.6

1:属性名称。

2:返回属性值的函数,第一个参数为当前元素的索引值,第二个参数为原先的属性值。

$("input[type='checkbox']").prop("checked");

removeProp(name)



attr   prop
html有的属性,可以用prop,自己加的属性,用attr



0 0