jQuery API 返回首页目录 | jQuery API 中英文对照版
css(properties)
css(properties)

把一个“名/值对”对象设置为所有匹配元素的样式属性。 这是一种在所有匹配的元素上设置大量样式属性的最佳方式。

返回值:jQuery

参数:

  • properties (Map): 要设置为样式属性的名/值对对象
 
示例:

为所有p元素设置color和background样式属性。

$("p").css({ color: "red", background: "blue" });

HTML 代码:

<p>Test Paragraph.</p>

结果:

<p style="color:red; background:blue;">Test Paragraph.</p>

 

css( properties )

Set a key/value object as style properties to all matched elements.

This serves as the best way to set a large number of style properties on all matched elements.

Return value: jQuery
Parameters:

  • properties (Map): Key/value pairs to set as style properties.
 

Example:

Sets color and background styles to all p elements.

 $("p").css({ color: "red", background: "blue" });  

Before:

 <p>Test Paragraph.</p>  
Result:
 <p style="color:red; background:blue
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog