加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长资讯 > 传媒 > 正文

jQuery1.3.2源码学习8:index 函数

发布时间:2018-09-03 19:13:05 所属栏目:传媒 来源:站长网
导读:// 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
// 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 行,使用了 === 来判断是否为同一个对象。

出处:博客园

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读