jQuery addClass() 方法

jQuery 教程 · 2019-03-27 10:57:36

实例

向第一个 <p> 元素添加一个类名:

$("button").click(function(){ $("p:first").addClass("intro"); });

定义和用法

addClass() 方法向被选元素添加一个或多个类名。

该方法不会移除已存在的 class 属性,仅仅添加一个或多个类名到 class 属性。

提示:如需添加多个类,请使用空格分隔类名。

语法

$(selector).addClass(classname,function(index,oldclass))

参数 描述
classname 必需。规定一个或多个要添加的类名称。
function(index,currentclass) 可选。规定返回一个或多个待添加类名的函数。
  • index - 返回集合中元素的 index 位置。
  • currentclass - 返回被选元素的当前类名。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

Web 2.0 Heroes

Web 2.0 Heroes

Bradley L. Jones / Wiley / 2008-04-14 / USD 24.99

Web 2.0 may be an elusive concept, but one thing is certain: using the Web as merely a means of retrieving and displaying information is history. Today?s Web is immediate, interactive, innovative. It ......一起来看看 《Web 2.0 Heroes》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器