jquery源代码分析之dom操作:removeClass

      removeClass(className):从匹配的元素中删除类

      @param (string) className

      @return (jQuery)

 

 1         /*
 2             1.对传进的参数value进行检测
 3         */
 4         if ( value && typeof value === "string" ) {
 5             /*
 6                 2.将参数value分割为数组classNames
 7             */
 8             classNames = value.split( rspace );
 9             /*
10                 3.对dom数组进行循环遍历
11             */
12             for ( i = 0, l = this.length; i < l; i++ ) {
13                 elem = this[ i ];
14                 /*
15                     4.判断当前dom的节点是否为ELEMENT类型
16                 */
17                 if ( elem.nodeType === 1 ) {
18                     /*
19                         5.如果classNames长度只有一个,直接进行赋值结束
20                     */
21                     if ( !elem.className && classNames.length === 1 ) {
22                         elem.className = value;
23 
24                     } else {
25                         /*
26                             6.保存dom原来的class值
27                         */
28                         setClass = " " + elem.className + " ";
29                         /*
30                             7.对classNames进行遍历,如果发现原class值没有包含,则添加进来
31                         */
32                         for ( c = 0, cl = classNames.length; c < cl; c++ ) {
33                             if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
34                                 setClass += classNames[ c ] + " ";
35                             }
36                         }
37                         elem.className = jQuery.trim( setClass );
38                     }
39                 }
40             }
41         }
42 
43         return this;

转载于:https://www.cnblogs.com/musickog/archive/2012/06/26/2563433.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值