css() 方法設(shè)置或返回被選元素的一個(gè)或多個(gè)樣式屬性。
如需返回指定的 CSS 屬性的值,請(qǐng)使用如下語法:
css("propertyname");
下面的例子將返回首個(gè)匹配元素的 background-color 值:
$("p").css("background-color");
如需設(shè)置指定的 CSS 屬性,請(qǐng)使用如下語法:
css("propertyname","value");
下面的例子將為所有匹配元素設(shè)置 background-color 值:
$("p").css("background-color","yellow");
如需設(shè)置多個(gè) CSS 屬性,請(qǐng)使用如下語法:
css({"propertyname":"value","propertyname":"value",...});
下面的例子將為所有匹配元素設(shè)置 background-color 和 font-size:
$("p").css({"background-color":"yellow","font-size":"200%"});
如需有關(guān) jQuery CSS 方法的完整內(nèi)容,請(qǐng)?jiān)L問我們的 jQuery CSS 操作參考手冊
如對(duì)本文有疑問,請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇