jQuery属性attr

 

设置多个属性/值对

为被选元素设置一个以上的属性和值。

语法

$(selector).attr({attribute:value, attribute:value ...})
比如:$("img").attr({width:"50",height:"80"});

    

 

使用函数来设置属性/值

设置被选元素的属性和值。

语法

$(selector).attr(attribute,function(index,oldvalue))
比如:$("button").click(function(){
$("img").attr("width",function(n,v){
return v-50;
});
});

 

 

返回属性值

返回被选元素的属性值。

语法

$(selector).attr(attribute)
比如:alert($("#b").attr("title"))

设置属性/值

设置被选元素的属性和值。

语法

$(selector).attr(attribute,value)
比如:$("#b").attr("title","test")

 

posted @ 2018-10-29 11:53  奉利民  阅读(136)  评论(0编辑  收藏  举报