jQuery prop() 与 removeProp()源码解读
2024-09-02 15:34:27
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 ];
});
}
最新文章
- Js添加消息提示数量
- .NET ORM 的 “SOD蜜”--零基础入门篇
- NSFileManeger
- 秀才提笔忘了字:javascript使用requestAnimationFrame实现动画
- qwt 6.1.0集成进Qt creator 2.8.1步骤
- js EasyUI前台 价格=数量*单价联动的实现
- thinkphp T方法
- SQL - 删掉数据库
- IZ65534: 'JAVA.LANG.CLASSFORMATERROR' ERROR FOR A VALID IDENTIFIER
- 【百度地图API】获取行政区域的边界
- 2015年最棒的10个 JavaScript 框架
- NPIO 导出Execl
- 在eclipse上使用github,向github中提交项目
- winform webbrowser如何强制使用ie11内核?
- vue-router query 传对象需要JSON.stringify()转化
- 搭建apache本地服务器·Mac
- linux 通过pid 寻找程序路径的最简单命令(pwdx)
- python之查询指定目录下的最新文件
- [OpenCV-Python] OpenCV 中的图像处理 部分 IV (一)
- Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果
热门文章
- gzhu 2013 Good Sequence 解题报告
- 《UML和模式应用》读书笔记(一)
- 转C++的一点点
- Linux服务:使用Supervisor管理进程
- 简单三步快速学会使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件(postgre使用实例)
- ftp连接服务器失败||或者Xshell链接错误:Could notconnect to '192.168.18.128' (port 22): Connection failed
- 构建一个简单的Angular工程
- android 自动生成jni C语言头文件
- linux学习 三 redhat
- nohup 命令 print 不能实时输出至 nohup.out