addClass: function( value ) {
var classes, elem, cur, clazz, j,
i = 0,
len = this.length,
proceed = typeof value === "string" && value; if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
jQuery( this ).addClass( value.call( this, j, this.className ) );
});
} if ( proceed ) {//如果传入的值不是字符串
// The disjunction here is for better compressibility (see removeClass)
//如果传入的是假值,"".match()
//core_rnotwhite 用于匹配非空格字符,且有g标识,匹配成功返回数组,匹配不成功返回[]
classes = ( value || "" ).match( core_rnotwhite ) || [];
//rclass = /[\t\r\n\f]/g
for ( ; i < len; i++ ) {
elem = this[ i ];
//如果elem是元素,cur会返回真值," "或者 " a b "
//替换tab符 回车 换行 换页
cur = elem.nodeType === 1 && ( elem.className ?
( " " + elem.className + " " ).replace( rclass, " " ) :
" "
);
if ( cur ) {
j = 0;
//遍历,如果原始class中不存在,字符串拼接
while ( (clazz = classes[j++]) ) {
if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
cur += clazz + " ";
}
}
elem.className = jQuery.trim( cur );//最后两边去空格 }
}
} return this;
}

removeClass、hasClass与addClass代码类似。

jQuery addClass() 源码解读的更多相关文章

  1. jQuery.Callbacks 源码解读二

    一.参数标记 /* * once: 确保回调列表仅只fire一次 * unique: 在执行add操作中,确保回调列表中不存在重复的回调 * stopOnFalse: 当执行回调返回值为false,则 ...

  2. jQuery toggleClass 源码解读

    toggleClass: function( value, stateVal ) { var type = typeof value;//值类型 if ( typeof stateVal === &q ...

  3. jQuery attr() 源码解读

    我们知道,$().attr()实质上是内部调用了jQuery.access方法,在调用时jQuery.attr作为回调传入.在通过种种判断(参看jQuery.access()方法)之后,取值和赋值最后 ...

  4. jquery.fileupload源码解读笔记

    基础编程风格 新建 test.html  和 test.js和 main.js和 无论哪种顺序 <body> <script src="/Sandeep/js/jquery ...

  5. jQuery.extend()源码解读

    // extend方法为jQuery对象和init对象的prototype扩展方法// 同时具有独立的扩展普通对象的功能jQuery.extend = jQuery.fn.extend = funct ...

  6. jQuery框架源码解读

    1.jQuery 1.9.1 parseJSON: function( data ) { // Attempt to parse using the native JSON parser first ...

  7. jQuery position() 源码解读

    position的代码比较简单... position: function() { if ( !this[ 0 ] ) { return; } var offsetParent, offset, el ...

  8. jquery offsetParent()源码解读

    offsetParent: function() { return this.map(function() { var offsetParent = this.offsetParent || docE ...

  9. jQuery removeAttr() 源码解读

    removeAttr比attr的代码要简单很多~~~ removeAttr: function( name ) { return this.each(function() { jQuery.remov ...

随机推荐

  1. hadoop 添加,删除节点

    http://www.cnblogs.com/tommyli/p/3418273.html

  2. hdu Integer Inquiry 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目意思:就是求大整数加法.有多个案例,每个案例之间要输出一个空格. #include < ...

  3. servlet与jsp理论知识讲解

    servlet是java服务器端编程,是运行在服务器上的.不同于以前的java小程序.                                                         ...

  4. HTML标签深入学习系列(1)——注释标签 <!-- -->

    一.HTML注释的语法 <!--注释内容--> 二.HTML注释的用处 1.普通注释(增强代码的可读性) 方便别人:方便其它程序员了解你的代码 方便自己:方便以后对自己代码的理解与修改等等 ...

  5. PIL 安装及使用

    我ubunto虚拟机自带的是python2.7,好像PIL也只支持到2.7. PIL包的安装 Debian/Ubunto Linux下直接安装: sudo apt-get install python ...

  6. Opencv— — Bias and Gain

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  7. BZOJ_1671_[Usaco2005 Dec]Knights of Ni 骑士_BFS

    Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...

  8. HDU5919 Sequence2

    传送门 这道题是主席树好题啊-- 题目大意:给定一个序列,每次给定一段区间,区间内所有不同的数第一次出现的位置排成一个序列,求这个序列的中位数. 其实求中位数并不是很难,只要我们能把这个序列中不同的数 ...

  9. 增加,删除GMS包

    1. device/hiteq/vtab_1050_standard/httek.mk BUILD_GMS:=yes GMS_VARIANT:=mini 2. rm out/target/produc ...

  10. tty初探 — uart驱动框架分析

    写在前面: 我们没有讲UART驱动,不过我们认为,只要系统学习了第2期,应该具备分析UART驱动的能力,小编做答疑几年以来,陆陆续续有不少人问到UART驱动怎么写,所以今天就分享一篇深度长文(1700 ...