最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery 學習之二 屬性相關

 更新時間:2010年11月23日 16:54:41   作者:  
jquery 學習之二 屬性相關資料,學習jquery的朋友可以參考下。
attr(name)
取得第一個匹配元素的屬性值。通過這個方法可以方便地從第一個匹配元素中獲取一個屬性的值。如果元素沒有相應屬性,則返回 undefined 。
Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned.
返回值
Object

參數(shù)
name (String) : 屬性名稱

示例
返回文檔中第一個圖像的src屬性值。

HTML 代碼:

<img src="test.jpg"/>
jQuery 代碼:

$("img").attr("src");
結果:

test.jpg
---------------------------------------------------------------------------------------------------------------------------------------
attr(properties)
將一個“名/值”形式的對象設置為所有匹配元素的屬性。
這是一種在所有匹配元素中批量設置很多屬性的最佳方式。 注意,如果你要設置對象的class屬性,你必須使用'className' 作為屬性名?;蛘吣憧梢灾苯邮褂?addClass( class ) 和 .removeClass( class ).
Set a key/value object as properties to all matched elements.
This serves as the best way to set a large number of properties on all matched elements. Note that you must use 'className' as key if you want to set the class-Attribute. Or use .addClass( class ) or .removeClass( class ).
返回值
jQuery

參數(shù)
properties (Map) : 作為屬性的“名/值對”對象

示例
為所有圖像設置src和alt屬性。

HTML 代碼:

<img/>
jQuery 代碼:

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

[ <img src= "test.jpg" alt:="Test Image" /> ]
---------------------------------------------------------------------------------------------------------------------------------------
attr(key,value)
為所有匹配的元素設置一個屬性值。
Set a single property to a value, on all matched elements.
返回值
jQuery

參數(shù)
key (String) : 屬性名稱

value (Object) : 屬性值

示例
為所有圖像設置src屬性。

HTML 代碼:

<img/>
<img/>
jQuery 代碼:

$("img").attr("src","test.jpg");
結果:

[ <img src= "test.jpg" /> , <img src= "test.jpg" /> ]
---------------------------------------------------------------------------------------------------------------------------------------
attr(key,fn)
為所有匹配的元素設置一個計算的屬性值。
不提供值,而是提供一個函數(shù),由這個函數(shù)計算的值作為屬性值。
Set a single property to a computed value, on all matched elements.
Instead of supplying a string value as described 'above', a function is provided that computes the value.
返回值
jQuery

參數(shù)
key (String) : 屬性名稱

fn (Function) : 返回值的函數(shù) 范圍:當前元素, 參數(shù): 當前元素的索引值

示例
把src屬性的值設置為title屬性的值。

HTML 代碼:

<img src="test.jpg"/>
jQuery 代碼:

$("img").attr("title", function() { return this.src });
結果:

<img src="test.jpg" title="test.jpg" />
---------------------------------------------------------------------------------------------------------------------------------------
removeAttr(name)
從每一個匹配的元素中刪除一個屬性
Remove an attribute from each of the matched elements.
返回值
jQuery

參數(shù)
name (String) : 要刪除的屬性名

示例
將文檔中圖像的src屬性刪除

HTML 代碼:

<img src="test.jpg"/>
jQuery 代碼:

$("img").removeAttr("src");
結果:

[ <img /> ]

相關文章

最新評論

元阳县| 温宿县| 出国| 伊吾县| 汉中市| 邵武市| 常熟市| 项城市| 环江| 班玛县| 洛阳市| 沅陵县| 阿荣旗| 温泉县| 沙湾县| 英超| 郴州市| 曲周县| 澄江县| 乳源| 拉孜县| 江华| 天全县| 普陀区| 隆子县| 涞源县| 那坡县| 朔州市| 山东省| 深水埗区| 鹰潭市| 都昌县| 两当县| 宜良县| 五台县| 龙井市| 当涂县| 彭泽县| 遂川县| 子长县| 游戏|