attr

英 ['?tr]? ?美 ['?tr]??

abbr.attractive 吸引人的,有魅力的

jquery attr() 方法 語法

作用:attr() 方法設(shè)定或傳回被選元素的屬性值。根據(jù)該方法不同的參數(shù),其工作方式也有所差異。

傳回屬性值:傳回被選元素的屬性值。

語法:$(selector).attr(attribute

#參數(shù):



#參數(shù)

說明

attribute? ??#規(guī)定取得其值的屬性。#設(shè)定屬性/值:設(shè)定被選元素的屬性和值。#語法:$(selector).attr(attribute, value

參數(shù):


#說明

attribute? ??規(guī)定屬性的名稱。value? ??規(guī)定屬性的值。?#規(guī)定屬性的值。?#規(guī)定屬性的值。

#使用函數(shù)設(shè)定屬性/值:設(shè)定被選元素的屬性和值。

#語法:$(selector).attr(attribute,function (index,oldvalue))

參數(shù):

#參數(shù)attribute? ??##function(index,oldvalue)#規(guī)定傳回屬性值的函數(shù)。此函數(shù)可接收並使用選擇器的index 值和目前屬性值。
##描述
規(guī)定屬性的名稱。
################設(shè)定多個屬性/值對:###為被選取元素設(shè)定一個以上的屬性和值。#########語法:###$(selector).attr({attribute:value, attribute:value ...})######### ####參數(shù):##################參數(shù)#######描述###########attribute:value### ###規(guī)定一個或多個屬性/值對。#############

jquery attr() 方法 範(fàn)例

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("img").attr("width","180");
  });
});
</script>
</head>
<body>
<img src="http://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg" />
<br />
<button>設(shè)置圖像的 width 屬性</button>
</body>
</html>
執(zhí)行實例 ?

#點擊 "執(zhí)行實例" 按鈕查看線上實例

#