📅  最后修改于: 2020-11-26 00:42:16             🧑  作者: Mango
jQuery CSS()方法用于获取(返回)或设置所选元素的样式属性或值。它有助于您获得一个或多个样式属性。
jQuery CSS()方法提供两种方法:
它用于获取指定CSS属性的值。
句法:
css("propertyname");
让我们以一个示例来演示此属性。
This is a heading
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.
输出:
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.
注意:上面的示例返回第一个匹配元素的背景色值。
此属性用于为所有匹配的元素设置特定的值。
句法:
css("propertyname","value");
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.
This paragraph has no background-color.
输出:
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.
它只是Set CSS属性的扩展。它有助于您将多个属性值添加在一起。
句法:
css({"propertyname":"value","propertyname":"value",...});
让我们以一个示例来演示此属性。在此示例中,我们为所有元素添加两个属性background-color和font-size。
This is a heading
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.
This paragraph has no background-color.
输出:
The background-color of this paragraph is red.
The background-color of this paragraph is green.
The background-color of this paragraph is blue.