jQuery - css() 方法(二十)

來源:互聯網
上載者:User
jQuery css() 方法

css() 方法設定或返回被選元素的一個或多個樣式屬性。 返回 CSS 屬性

如需返回指定的 CSS 屬性的值,請使用如下文法:

css("propertyname");

下面的例子將返回首個匹配元素的 background-color 值: 執行個體

$("p").css("background-color");

親自試一試 設定 CSS 屬性

如需設定指定的 CSS 屬性,請使用如下文法:

css("propertyname","value");

下面的例子將為所有匹配元素設定 background-color 值: 執行個體

$("p").css("background-color","yellow");

親自試一試 設定多個 CSS 屬性

如需設定多個 CSS 屬性,請使用如下文法:

css({"propertyname":"value","propertyname":"value",...});

下面的例子將為所有匹配元素設定 background-color 和 font-size: 執行個體

$("p").css({"background-color":"yellow","font-size":"200%"});

親自試一試 jQuery HTML 參考手冊

如需有關 jQuery CSS 方法的完整內容,請訪問我們的 jQuery CSS 操作參考手冊

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.