栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jquery 学习之二 属性(类)

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jquery 学习之二 属性(类)

addClass(class) 为每个匹配的元素添加指定的类名。 Adds the specified class(es) to each of the set of matched elements. 返回值

jQuery

参数

class (String) : 一个或多个要添加到元素中的CSS类名,请用空格分开

示例

为匹配的元素加上 'selected' 类

HTML 代码:

Hello

jQuery 代码:

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

结果:

[

Hello

]

为匹配的元素加上 selected highlight 类

HTML 代码:

Hello

jQuery 代码:

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

结果:

[

Hello

] ------------------------------------------------------------------------------------------------------------------------------ removeClass(class) 从所有匹配的元素中删除全部或者指定的类。 Removes all or the specified class(es) from the set of matched elements. 返回值

jQuery

参数

class (String) : (可选) 一个或多个要删除的CSS类名,请用空格分开

示例

从匹配的元素中删除 'selected' 类

HTML 代码:

Hello

jQuery 代码:

$("p").removeClass("selected");

结果:

[

Hello

]

删除匹配元素的所有类

HTML 代码:

Hello

jQuery 代码:

$("p").removeClass();

结果:

[

Hello

] ------------------------------------------------------------------------------------------------------------------------------ toggleClass(class) 如果存在(不存在)就删除(添加)一个类。 Adds the specified class if it is not present, removes the specified class if it is present. 返回值

jQuery

参数

class (String) :CSS类名

示例

为匹配的元素切换 'selected' 类

HTML 代码:

Hello

Hello Again

jQuery 代码:

$("p").toggleClass("selected");

结果:

[

Hello

,

Hello Again

]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/114966.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号