最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

jquery学习之二属性(类)_jquery

来源:动视网 责编:小采 时间:2020-11-27 20:55:57
文档

jquery学习之二属性(类)_jquery

jquery学习之二属性(类)_jquery:addClass(class) 为每个匹配的元素添加指定的类名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 参数 class (String) : 一个或多个要添加到元素中的CSS类名,请用空格分开 示例 为匹配的元素加
推荐度:
导读jquery学习之二属性(类)_jquery:addClass(class) 为每个匹配的元素添加指定的类名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 参数 class (String) : 一个或多个要添加到元素中的CSS类名,请用空格分开 示例 为匹配的元素加


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

] if ($ != jQuery) { $ = jQuery.noConflict(); }

文档

jquery学习之二属性(类)_jquery

jquery学习之二属性(类)_jquery:addClass(class) 为每个匹配的元素添加指定的类名。 Adds the specified class(es) to each of the set of matched elements. 返回值 jQuery 参数 class (String) : 一个或多个要添加到元素中的CSS类名,请用空格分开 示例 为匹配的元素加
推荐度:
标签: 属性 jQuery 之二
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top