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://codercto.com/courses/l/35.html

查看所有标签

XMPP

XMPP

Peter Saint-Andre、Kevin Smith、Remko TronCon / O'Reilly Media / 2009-5-4 / USD 39.99

This practical book provides everything you need to know about the Extensible Messaging and Presence Protocol (XMPP). This open technology for real-time communication is used in many diverse applicati......一起来看看 《XMPP》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

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

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具