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

为每个匹配的元素添加指定的类名。

返回值:jQuery

参数:

  • class (String): 要添加到元素中的CSS类名
 

示例:

$("p").addClass("selected")

HTML 代码:

<p>Hello</p>

结果:

[ <p class="selected">Hello</p> ]

 
addClass( class )

Adds the specified class(es) to each of the set of matched elements.

Return value: jQuery
Parameters:

  • class (String): One or more CSS classes to add to the elements
 

Example:

 $("p").addClass("selected")  
Before:
 <p>Hello</p>  
Result:
 [ <p class="selected">Hello</p> ]  

Example:

 $("p").addClass("selected highlight")  
Before:
 <p>Hello</p>  
Result:
 [ <p class="selected highlight">Hello</p> ]  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog