jQuery 擁有三種用於 CSS 操作的重要函式:
$(selector).css(name,value)
$(selector).css({properties})
$(selector).css(name)
函式 css(name,value) 為所有匹配元素的給定 CSS 屬性設定值:
$(selector).css(name,value)
$("p").css("background-color","red");
親自試一試
函式 css({properties}) 同時為所有匹配元素的一系列 CSS 屬性設定值:
$(selector).css({properties})
$("p").css({"background-color":"red","font-size":"200%"});
親自試一試
函式 css(name) 返回指定的 CSS 屬性的值:
$(selector).css(name)
$(this).css("background-color");
親自試一試
jQuery 擁有兩種用於尺寸操作的重要函式:
$(selector).height(value)
$(selector).width(value)
函式 height(value) 設定所有匹配元素的高度:
$(selector).height(value)
$("#id100").height("200px");
親自試一試
函式 width(value) 設定所有匹配元素的寬度:
$(selector).width(value)
$("#id200").width("300px");
親自試一試
CSS 屬性 | 描述 |
---|---|
$(selector).css(name,value) | 為匹配元素設定樣式屬性的值 |
$(selector).css({properties}) | 為匹配元素設定多個樣式屬性 |
$(selector).css(name) | 獲得第一個匹配元素的樣式屬性值 |
$(selector).height(value) | 設定匹配元素的高度 |
$(selector).width(value) | 設定匹配元素的寬度 |
[admin via ] jQuery CSS 函式已經有422次圍觀