jQuery1.3.2 源码学习-8 index 函数
2010-04-24 21:13
477 查看
// Determine the position of an element within
// the matched set of elements
160 index: function( elem ) {
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
elem && elem.jquery ? elem[0] : elem
, this );
},
160 行的 index 函数用来返回元素在查询结果中的下标。下标从 0 开始,如果没有找到匹配的元素,那么返回 -1。
注意:inArray 函数定义在 1086 行。
1086 inArray: function( elem, array ) {
1087 for ( var i = 0, length = array.length; i < length; i++ )
1088 // Use === because on IE, window == document
1089 if ( array[ i ] === elem )
1090 return i;
1091
1092 return -1;
1093 },
这是一个非常简单的函数,检查在数组中是否存在一个特定的元素,注意第 1089 行,使用了 === 来判断是否为同一个对象。
![](http://images.cnblogs.com/cnblogs_com/haogj/242334/r_ms.jpg)
// the matched set of elements
160 index: function( elem ) {
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
elem && elem.jquery ? elem[0] : elem
, this );
},
160 行的 index 函数用来返回元素在查询结果中的下标。下标从 0 开始,如果没有找到匹配的元素,那么返回 -1。
注意:inArray 函数定义在 1086 行。
1086 inArray: function( elem, array ) {
1087 for ( var i = 0, length = array.length; i < length; i++ )
1088 // Use === because on IE, window == document
1089 if ( array[ i ] === elem )
1090 return i;
1091
1092 return -1;
1093 },
这是一个非常简单的函数,检查在数组中是否存在一个特定的元素,注意第 1089 行,使用了 === 来判断是否为同一个对象。
![](http://images.cnblogs.com/cnblogs_com/haogj/242334/r_ms.jpg)
相关文章推荐
- jQuery1.3.2 源码学习-6 size 和 get 函数
- jQuery1.3.2 源码学习-3 init 函数分析 - 1
- jQuery1.3.2 源码学习-4 init 函数分析 - 2
- jQuery1.3.2 源码学习-7 setArray,each 函数
- jQuery1.3.2 源码学习-5 jQuery 中的原型
- 【代码片-1】 jQuery源码学习(版本1.11)-事件处理-实例函数
- jquery 源码学习(四)构造jQuery对象-工具函数
- jQuery源码学习(版本1.11)-事件处理-工具函数jQuery.event
- jQuery源码逐行分析学习02(第一部分:jQuery的一些变量和函数)
- jQuery1.3.2 源码学习 -1 $ 是什么?jQuery 又是什么?
- jquery源码学习笔记:自执行匿名函数剖析
- jQuery1.3.2 源码学习 -2 两个重要的正则表达式
- jquery源码分析学习地址
- 【转】jQuery源码分析-03构造jQuery对象-源码结构和核心函数
- jQuery学习7 操作JavaScript对象和集合的函数
- [TensorFlow 学习笔记-08]tf.pad函数源码解析
- jQuery源码学习7——实例成员
- jQuery源码解读2:.extend()函数
- Java源码学习之Integer类(二)——1.8新增的几个函数和变量
- jQuery源码-解除绑定事件函数unbind