jQuery addClass() 源码解读
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() 源码解读的更多相关文章
- jQuery.Callbacks 源码解读二
一.参数标记 /* * once: 确保回调列表仅只fire一次 * unique: 在执行add操作中,确保回调列表中不存在重复的回调 * stopOnFalse: 当执行回调返回值为false,则 ...
- jQuery toggleClass 源码解读
toggleClass: function( value, stateVal ) { var type = typeof value;//值类型 if ( typeof stateVal === &q ...
- jQuery attr() 源码解读
我们知道,$().attr()实质上是内部调用了jQuery.access方法,在调用时jQuery.attr作为回调传入.在通过种种判断(参看jQuery.access()方法)之后,取值和赋值最后 ...
- jquery.fileupload源码解读笔记
基础编程风格 新建 test.html 和 test.js和 main.js和 无论哪种顺序 <body> <script src="/Sandeep/js/jquery ...
- jQuery.extend()源码解读
// extend方法为jQuery对象和init对象的prototype扩展方法// 同时具有独立的扩展普通对象的功能jQuery.extend = jQuery.fn.extend = funct ...
- jQuery框架源码解读
1.jQuery 1.9.1 parseJSON: function( data ) { // Attempt to parse using the native JSON parser first ...
- jQuery position() 源码解读
position的代码比较简单... position: function() { if ( !this[ 0 ] ) { return; } var offsetParent, offset, el ...
- jquery offsetParent()源码解读
offsetParent: function() { return this.map(function() { var offsetParent = this.offsetParent || docE ...
- jQuery removeAttr() 源码解读
removeAttr比attr的代码要简单很多~~~ removeAttr: function( name ) { return this.each(function() { jQuery.remov ...
随机推荐
- Android高手应该精通哪些内容
很多Android开发者已经度过了初级.中级,如何成为一个Android高手呢? Android123就各个级别的程序员应该掌握哪些内容作为下面分类. 一.初级 1. 拥有娴熟的Java基础,理解设计 ...
- 用windows的批处理文件批量更改文件后缀
[转自]http://jingyan.baidu.com/article/e9fb46e196ea187521f7661a.html 无需软件批量修改文件后缀名?怎么通过命令行批量修改文件后缀名?有 ...
- 细谈HTML解析模块
细谈HTML解析模块 Html在网页中所占的位置,用一个简单直观的图给展示一下:
- codeforces 665A A. Buses Between Cities(水题)
题目链接: A. Buses Between Cities time limit per test 1 second memory limit per test 256 megabytes input ...
- CodeForces - 762E:Radio stations (CDQ分治||排序二分)
In the lattice points of the coordinate line there are n radio stations, the i-th of which is descri ...
- 点分治 [IOI2011]Race
BZOJ2599. 放板子.利用agc009-D 代码简洁了很多 #include <bits/stdc++.h> #define N 200005 using namespace std ...
- Win32编程点滴5 - 响应ActiveX控件的事件
在最近的一篇文章中说到了,如何创建ActiveX,这次我们来响应事件.这次,我们将创建一个类:CGeneralEventSink,它能够响应任何Dispatch事件(事件的接口继承与IDispatch ...
- zynq交叉编译环境设置
环境准备 Vmware 虚拟机:ubuntu14.04 下载安装文件 环境设置 按照上面地址下载 xilinx-2011.09-50-arm-xilinx-linux-gnueabi.bin 将das ...
- sqlServer:convert()函数
在oracle中对于时间格式的转换用到的比较多,相对也比较了解,现在换了新的项目组,使用sqlserver数据库,需要对这个数据库的一些常用函数进行重新学习和熟悉,现在根据w3c及网上博文对conve ...
- 利用python数据分析panda学习笔记之Series
1 Series a:类似一维数组的对象,每一个数据与之相关的数据标签组成 b:生成的左边为索引,不指定则默认从0开始. from pandas import Series,DataFrame imp ...