源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jQuery学习笔记之jQuery.fn.init()的参数分析

  • 时间:2020-04-22 01:58 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jQuery学习笔记之jQuery.fn.init()的参数分析
[img]http://files.jb51.net/file_images/article/201406/201406091021552.png[/img] 从return new jQuery.fn.init( selector, context, rootjQuery )中可以看出 参数selector和context是来自我们在调用jQuery方法时传过来的. 那么selector和context都有哪些可能. [img]http://files.jb51.net/file_images/article/201406/201406091021553.jpg[/img]   对于表格中的4~9行中的可能做具体分析. [img]http://files.jb51.net/file_images/article/201406/201406091021554.png[/img] 如果selector是字符串,则首先检测是html代码还是#id. 126行的if语句:以"<"开头,以">"结尾,且长度>=3.则假设额这个是HTML片段,这里只是假设不一定就是合肥的html代码.比如"<div><guofsfsdfd>"; 130行的else:表示不是html代码.这个时候用正则表达式来检测. [img]http://files.jb51.net/file_images/article/201406/201406091021555.png[/img] 我对正则不是很懂.不过大致可以看懂,匹配的是html和id.匹配的结果赋值给match. 分析完了selector,context参数后,我们是不是忘了rootjQuery参数. 这个参数是jQuery内部定义的.不是我们手动从外部传入的. 从名字上我们大概能猜出这个参数的大概情况了:根部的jQuery对象. 看源码定义: [img]http://files.jb51.net/file_images/article/201406/201406091021556.jpg[/img] 那么什么情况下,程序会用到这个参数呢? 1.当document.getElementById()查找失败, [img]http://files.jb51.net/file_images/article/201406/201406091021557.jpg[/img] 2.selector是函数: [img]http://files.jb51.net/file_images/article/201406/201406091021558.jpg[/img] 3.selector是选择器表达式,且未指定context; [img]http://files.jb51.net/file_images/article/201406/201406091021559.jpg[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部