jQuery css()
訪問匹配元素的樣式屬性。
jQuery 1.8中,當你使用CSS屬性在css()或animate()中,我們將根據瀏覽器自動加上字首(在適當的時候),比如("user-select", "none"); 在Chrome/Safari瀏覽器中我們將設定為"-webkit-user-select", Firefox會使用"-moz-user-select", IE10將使用"-ms-user-select".
要訪問的屬性名稱
一個或多個CSS屬性組成的一個陣列
要設定為樣式屬性的名/值對
屬性名,屬性值
1:屬性名
2:此函式返回要設定的屬性值。接受兩個引數,index為元素在物件集合中的索引位置,value是原先的屬性值。
取得第一個段落的color樣式屬性的值。
$("p").css("color");
將所有段落的字型顏色設為紅色並且背景為藍色。
$("p").css({ "color": "#ff0011", "background": "blue" });
將所有段落字型設為紅色
$("p").css("color","red");
逐漸增加div的大小
$("div").click(function() { $(this).css({ width: function(index, value) { return parseFloat(value) * 1.2; }, height: function(index, value) { return parseFloat(value) * 1.2; } }); });
以上就是jQuery css()的全部內容,希望這篇jQuery css()能幫到你。
[admin via ] jQuery css()方法已經有408次圍觀