jQuery prop() 与 removeProp()源码解读
prop()

prop: function( elem, name, value ) {
var ret, hooks, notxml,
nType = elem.nodeType;
// don't get/set properties on text, comment and attribute nodes
//标签不存在或者是文本、属性、注释节点
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
return;
}
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
if ( notxml ) {
// 属性中的for与class涉及到保留字,所以通过propFix分别对应到htmlFor和className
// propFix: {
// "for": "htmlFor",
// "class": "className"
// }
name = jQuery.propFix[ name ] || name;
// propHooks: {
// tabIndex: {
// get: function( elem ) {
// return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
// elem.tabIndex :
// -1;
// }
// }
// }
//hasAttribute IE9+
//rfocusable 用于检测可以处于焦点的表单元素正则
hooks = jQuery.propHooks[ name ];
}
if ( value !== undefined ) {//赋值
return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
ret :
( elem[ name ] = value );
} else {//取值
return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
ret :
elem[ name ];
}
}
removeProp()
removeProp: function( name ) {
return this.each(function() {
delete this[ jQuery.propFix[ name ] || name ];
});
}
jQuery prop() 与 removeProp()源码解读的更多相关文章
- 第二十五课:jQuery.event.trigger的源码解读
本课主要来讲解jQuery.event.trigger的源码解读. trigger = function(event, data, elem, onlyHandlers){ if(elem & ...
- jQuery scrollLeft()与scrollTop() 源码解读
这里的实现也很容易懂,通过jQuery的静态方法each给jQuery的原型添加scrollLeft和scrollTop方法. 这里在取值时它把window和普通的element做了区分 如果是win ...
- jQuery插件pagination.js源码解读
pagination的github地址:https://github.com/gbirke/jquery_pagination 公司用的是1.2的版本,所以我就读1.2的了. jQuery.fn.pa ...
- 第二十四课:jQuery.event.remove,dispatch的源码解读
本课还是来讲解一下jQuery是如何实现它的事件系统的.这一课我们先来讲一下jQuery.event.remove的源码解读. remove方法的目的是,根据用户传参,找到事件队列,从里面把匹配的ha ...
- 第二十三课:jQuery.event.add的原理以及源码解读
本课主要来讲解一下jQuery是如何实现它的事件系统的. 我们先来看一个问题: 如果有一个表格有100个tr元素,每个都要绑定mouseover/mouseout事件,改成事件代理的方式,可以节省99 ...
- jQuery.Callbacks 源码解读二
一.参数标记 /* * once: 确保回调列表仅只fire一次 * unique: 在执行add操作中,确保回调列表中不存在重复的回调 * stopOnFalse: 当执行回调返回值为false,则 ...
- jquery源码解读
最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐进增强)优雅的处理能 ...
- jQuery源码解读----part 2
分离构造器 通过new操作符构建一个对象,一般经过四步: A.创建一个新对象 B.将构造函数的作用域赋给新对象(所以this就指向了这个新对象) C.执行构造函数中的代码 D.返回这个新对象 最后一点 ...
- jquery中的 parseJSON() 源码分析
parseJSON: function( data ) { // Attempt to parse using the native JSON parser first if ( window.JSO ...
随机推荐
- BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...
- Windows下Tesseract4.0识别与中文手写字体训练
一 . tesseract 4.0 安装及使用 1. tesseract 4.0 安装 安装包下载地址: http://digi.bib.uni-mannheim.de/tesseract/tesse ...
- SqlSession
- Windows_Program_Via_C_Translate_Win32编程的背景知识/基础知识_包括基本输入输出机制介绍
Some Basic Background Story of The Win32 APIs Win32 API背景故事/背景知识 The Win32 application programming i ...
- Spring Boot配置多个DataSource
使用Spring Boot时,默认情况下,配置DataSource非常容易.Spring Boot会自动为我们配置好一个DataSource. 百牛信息技术bainiu.ltd整理发布于博客园 如果在 ...
- bzoj4289
最短路 很容易想到边和边之间连边,但是这样菊花图就完蛋了 我们想办法优化一下,能不能不要每条边都连. 考虑查分,把一个点的出边串起来,这样就行了,每条无向边拆成两条就能保证了 #include< ...
- Oracle中CASE WHEN的用法实例
实例演示: (1)查询表users中的数据. select u.id,u.realname,U.SEX from users u; 查询结果如下 ID REALNAME SEX 1 10082 ...
- 【219】◀▶ IDL 数学函数说明
参考:Math - Miscellaneous Routines参考:Math - Statistical Tools Routines 01 ABS 绝对值. 02 SQRT 平方根. 03 ...
- org.apache.catalina.LifecycleException报错解决方法
严重: A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catalin ...
- SpringMVC数据绑定一(基本类型、数组和对象(简单对象、层级对象、多参数对象))
一.int和Integer类型 如:参数为int类型的请求 @Controller public class TestController { @RequestMapping(value=" ...