DIV CSS 佈局教程網

jQuery css() 方法示例詳解
編輯:JavaScript綜合知識     

css() 方法用於設置或返回被選元素的一個或多個樣式屬性,本文透過幾個範例說明其用法。

設置 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%"});

設置單個屬性時傳入「屬性名、屬性值」兩個參數;一次設置多個屬性時則傳入一個物件,逐一列出屬性名與對應值,語法簡潔直觀。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved