attr
英 ['?tr]? ?美 ['?tr]??
abbr.attractive 吸引人的,有魅力的
jquery attr() 方法 語法
作用:attr() 方法設(shè)定或傳回被選元素的屬性值。根據(jù)該方法不同的參數(shù),其工作方式也有所差異。
傳回屬性值:傳回被選元素的屬性值。
語法:$(selector).attr(attribute
#參數(shù):
#參數(shù)
說明
#語法: |
參數(shù):
#說明
value? ?? | |
#使用函數(shù)設(shè)定屬性/值:設(shè)定被選元素的屬性和值。
#語法:$(selector).attr(attribute,function (index,oldvalue))
參數(shù):
##描述 | |
規(guī)定屬性的名稱。 | ##function(index,oldvalue) |
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í)行實例" 按鈕查看線上實例