jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
css(name)
css(name)

访问第一个匹配元素的样式属性。使用这个方法可以很容易地取得第一个匹配元素的样式属性的值。

返回值:String

参数:

  • name (String): 要访问的属性名称
 

示例:

取得第一个段落的color样式属性的值。

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

HTML 代码:

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

结果:

"red"

示例:

取得第一个段落的font-weight样式属性的值。

$("p").css("font-weight");

HTML 代码:

<p style="font-weight: bold;">Test Paragraph.</p>

结果:

"bold"

 
css( name )

Access a style property on the first matched element. This method makes it easy to retrieve a style property value from the first matched element.

Return value: String
Parameters:

  • name (String): The name of the property to access.
 

Example:

Retrieves the color style of the first paragraph

 $("p").css("color");  
Before:
 <p style="color:red;">Test Paragraph.</p>  

Result:

 "red"

Example:

Retrieves the font-weight style of the first paragraph.

 $("p").css("font-weight");  
Before:
 <p style="font-weight: bold;">Test Paragraph.</p>  
Result:
 "bold"