jQuery中index是用来查找匹配的元素并且返回索引值 从0开始
html代码
<ul>
<div></div>
<li></li>
<li id="foo">foo</li>
<li id="bar">bar</li>
<li id="baz">baz</li>
</ul>
js代码
console.log($('li').index(document.getElementById('bar'))); //返回值为2 给与一个dom对象返回这个对象在集合中的位置
console.log($('li').index($('#bar'))); //返回值为2 给予一个jQuery对象返回这个对象在集合中的位置
console.log($('li').index($('li:gt(2)'))); //返回值为3 给与一组jQuery对象并且返回这组对象中第一个对象出现的位置
console.log($('#foo').index('li')); //返回值为1 给予一个选择器并且返回foo在所有li对象中出现的位置
console.log($('#bar').index()); //返回值为3 没有参数 返回bar在所有的同辈元素中出现的位置