示例:http://jsfiddle.net/peeter/ePMFe/
它返回索引为-1,而不是实际索引。任何想法都将不胜感激。
最佳答案
因为您的 jQuery 数组是 UL,而您正在搜索 LI。
console.log($("#myul li").index(tab));
应该可以正常工作
关于jquery - 为什么 .index() 函数不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5619673/