加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 业界 > 正文

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

发布时间:2018-09-05 20:03:12 所属栏目:业界 来源:站长网
导读:// 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 行,行使了 === 来判定是否为统一个工具。

出处:博客园

(编辑:河北网)

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

    热点阅读