1. preFilter: {
  2. "ATTR": function( match ) {
  3. //属性名解码
  4. match[1] = match[1].replace( runescape, funescape );
  5.  
  6. // Move the given value to match[3] whether quoted or unquoted
  7. //属性解码
  8. match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
  9.  
  10. //若判断符为~=,则在属性值两边加上空格
  11. if ( match[2] === "~=" ) {
  12. match[3] = " " + match[3] + " ";
  13. }
  14.  
  15. //返回前4个元素
  16. return match.slice( 0, 4 );
  17. },
  18.  
  19. "CHILD": function( match ) {
  20. /* matches from matchExpr["CHILD"]
  21. 1 type (only|nth|...)
  22. 2 what (child|of-type)
  23. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  24. 4 xn-component of xn+y argument ([+-]?\d*n|)
  25. 5 sign of xn-component
  26. 6 x of xn-component
  27. 7 sign of y-component
  28. 8 y of y-component
  29. */
  30. //match[1]:(only|first|last|nth|nth-last)
  31. //match[2]: (child|last-child|of-type|last-of-type)
  32. //match[3]: (even|odd)
  33. //match[4]、match[5]: an+b中的a,b
  34.  
  35. //match[1]变成小写
  36. match[1] = match[1].toLowerCase();
  37.  
  38. //如果match[1]是"nth"
  39. if ( match[1].slice( 0, 3 ) === "nth" ) {
  40. // nth-* requires argument
  41. //若选择器括号内没有有效参数,则抛出异常
  42. if ( !match[3] ) {
  43. Sizzle.error( match[0] );
  44. }
  45.  
  46. // numeric x and y parameters for Expr.filter.CHILD
  47. // remember that false/true cast respectively to 0/1
  48. /*
  49. * 下面先以nth-child()为例介绍一下语法,以便更好的理解下面代码的作用
  50. * nth-child允许的几种使用方式如下:
  51. * :nth-child(even)
  52. * :nth-child(odd)
  53. * :nth-child(3n)
  54. * :nth-child(+2n+1)
  55. * :nth-child(2n-1)
  56. * 下面代码中赋值号左侧的match[4]、match[5]用于分别记录括号内n前及n后的数值,包括正负号
  57. * 对于:nth-child(even)和:nth-child(odd)来说,match[4]为空,
  58. * 所以返回 2 * (match[3] === "even" || match[3] === "odd")的计算结果
  59. * 因为在js中true=1,false=0,所以(match[3] === "even" || match[3] === "odd")等于1
  60. * 因此,2 * (match[3] === "even" || match[3] === "odd")的计算结果为2
  61. *
  62. * 等号右侧的“+”的作用是强制类型转换,将之后的字符串转换成数值类型
  63. */
  64. match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
  65. match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
  66.  
  67. // other types prohibit arguments
  68. //若非nth起头的其它CHILD类型选择器带有括号说明,则抛出异常
  69. } else if ( match[3] ) {
  70. Sizzle.error( match[0] );
  71. }
  72.  
  73. return match;
  74. },
  75.  
  76. "PSEUDO": function( match ) {
  77. var excess,
  78. unquoted = !match[6] && match[2];
  79.  
  80. if ( matchExpr["CHILD"].test( match[0] ) ) {
  81. return null;
  82. }
  83.  
  84. // Accept quoted arguments as-is
  85. if ( match[3] ) {
  86. match[2] = match[4] || match[5] || "";
  87.  
  88. // Strip excess characters from unquoted arguments
  89. } else if ( unquoted && rpseudo.test( unquoted ) &&
  90. // Get excess from tokenize (recursively)
  91. (excess = tokenize( unquoted, true )) &&
  92. // advance to the next closing parenthesis
  93. (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
  94.  
  95. // excess is a negative index
  96. match[0] = match[0].slice( 0, excess );
  97. match[2] = unquoted.slice( 0, excess );
  98. }
  99.  
  100. // Return only captures needed by the pseudo filter method (type and argument)
  101. return match.slice( 0, 3 );
  102. }
  103. },
 

【jQuery源码】preFilter的更多相关文章

  1. jQuery源码分析系列

    声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 版本截止到2013.8.24 jQuery官方发布最新的的2.0.3为准 附上每一章的源码注释分析 :https://git ...

  2. jQuery源码学习感想

    还记得去年(2015)九月份的时候,作为一个大四的学生去参加美团霸面,结果被美团技术总监教育了一番,那次问了我很多jQuery源码的知识点,以前虽然喜欢研究框架,但水平还不足够来研究jQuery源码, ...

  3. Jquery源码学习(第一天)

    jQuery是面向对象的设计通过window.$ = window.jQuery = $; 向外提供接口,将$挂在window下,外部就可以使用$和jQuery $("#div1" ...

  4. jQuery源码 Ajax模块分析

    写在前面: 先讲讲ajax中的相关函数,然后结合函数功能来具体分析源代码. 相关函数: >>ajax全局事件处理程序 .ajaxStart(handler) 注册一个ajaxStart事件 ...

  5. jQuery源码:从原理到实战

    jQuery源码:从原理到实战 jQuery选择器对象 $(".my-class"); document.querySelectorAll*".my-class" ...

  6. 【菜鸟学习jquery源码】数据缓存与data()

    前言 最近比较烦,深圳的工作还没着落,论文不想弄,烦.....今天看了下jquery的数据缓存的代码,参考着Aaron的源码分析,自己有点理解了,和大家分享下.以后也打算把自己的jquery的学习心得 ...

  7. 从jquery源码中看类型判断和数组的一些操作

    在深入看jquery源码中,大家会发现源码写的相当巧妙.那我今天也通过几个源码中用到的技巧来抛砖引玉,希望大家能共同研究源码之精华,不要囫囵吞枣. 1.将类数组转化成数组 我想大家首先想到的方法是fo ...

  8. 读艾伦的jQuery的无new构建,疑惑分析——jquery源码学习一

    背景: 有心学习jquery源码,苦于自己水平有限,若自己研究,耗时耗力,且读懂之日无期. 所以,网上寻找高手的源码分析.再经过自己思考,整理,验证.以求有所收获. 此篇为读高手艾伦<jQuer ...

  9. JQuery源码解析(一)

    写在前面:本<JQuery源码解析>系列是基于一些前辈们的文章进行进一步的分析.细化.修改而写出来的,在这边感谢那些慷慨提供科普文档的技术大拿们. 要查阅JQ的源文件请下载开发版的JQ.j ...

  10. 读jQuery源码 - Deferred

    Deferred首次出现在jQuery 1.5中,在jQuery 1.8之后被改写,它的出现抹平了javascript中的大量回调产生的金字塔,提供了异步编程的能力,它主要服役于jQuery.ajax ...

随机推荐

  1. (求树的直径)Warm up -- HDU -- 4612

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 给一个无向图, 加上一条边后,求桥至少有几个: 那我们加的那条边的两个顶点u,v:一定是u,v之 ...

  2. Codeforces735C Tennis Championship 2016-12-13 12:06 77人阅读 评论(0) 收藏

    C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. Lucene 中自定义排序的实现

    使用Lucene来搜索内容,搜索结果的显示顺序当然是比较重要的.Lucene中Build-in的几个排序定义在大多数情况下是不适合我们使用的.要适合自己的应用程序的场景,就只能自定义排序功能,本节我们 ...

  4. How Many Tables HDOJ

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. web.xml中Filter,Listener,Servlet的区别

    一.Servlet Servlet是基本的服务端程序,他来自接口Servlet,接口中有方法service.而Servlet的一个重要实现类,则是tomcat服务器的核心,那就是HttpServlet ...

  6. SqlServer数据库同时备份到两台服务器上(并自动删除过期文件)

    数据库同时备份到两台服务器上(并自动删除过期文件) 举例 :(本地)服务器A: IP :192.168.1.1 (远程)服务器B: IP :192.168.1.2 数据库版本:SqlServer200 ...

  7. 创建/读取/删除Session对象

    //创建Session对象 Session["userName"] = "顾德博";//保存,这里可以存储任意类型的数据,包括对象.集合等 Session.Ti ...

  8. Plugin 'FEDERATED' is disabled. /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist

    问题:在linux上安装mysql的时候出现Plugin ‘FEDERATED’ is disabled. /usr/sbin/mysqld: Table ‘mysql.plugin’ doesn’t ...

  9. PyMysql复习

    参考:http://www.cnblogs.com/liwenzhou/p/8032238.html 使用pycharm操作数据库. 填一个数据库名,User:填root 填写要连接的数据库. 建表. ...

  10. zoj4019 Schrödinger's Knapsack(dp)

    题意:有两种物品分别为n,m个,每种物品对应价值k1,k2.有一个容量为c的背包,每次将一个物品放入背包所获取的价值为k1/k2*放入物品后的剩余体积.求问所获取的最大价值. 整体来看,优先放入体积较 ...