欧美国产另类久热|951超碰伊人久久|伊人影视久久久久|色婷婷亚洲小电影|色东京热69XX|婷婷玖玖深爱网|加勒比东京热网站|无码A级毛片在线观看|一级a毛一级a看|中文字幕人妻欧美

jquery獲取對象在數(shù)組對象中的索引值
來源:易賢網(wǎng) 閱讀:2003 次 日期:2016-06-24 10:25:27
溫馨提示:易賢網(wǎng)小編為您整理了“jquery獲取對象在數(shù)組對象中的索引值”,方便廣大網(wǎng)友查閱!

在jquery中有通過索引獲取該jquery對象的,單如何通過對象獲取該對象所在的索引呢?

jquery提供了index(jqueryobj對象)的方法該方法的返回值是索引值,當(dāng)對象數(shù)組中沒有該對象時,

返回的是-1.

語法

var index = $(.class).index($(#id));

上面的語法意思是:在所有.class類對象中找到id為id的jquery對象的索引

看實例代碼:

html代碼

代碼如下:

<div class=forasp id=www>網(wǎng)站</div>

<div class=forasp id=forasp>制作</div>

<div class=forasp id=dian>學(xué)習(xí)</div>

<div class=forasp id=cn>anypoetry.com</div>

jquery代碼

代碼如下:

var obj_a = $(.forasp);

alert(obj_a.index($(#www)));

alert(obj_a.index($(#dian)));

alert(obj_a.index($(#notexists)));

上面的返回值分別是 0 2 和-1.

這樣就獲得了jquery對象在數(shù)組中的索引。

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:jquery獲取對象在數(shù)組對象中的索引值
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)