1
爲什麼jQuery索引在數組中返回-1?Jquery索引在搜索0時返回-1
var myArray = [0,4,8];
document.write('<br/>8 is at index : ' + $(myArray).index(8));
document.write('<br/>4 is at index : ' + $(myArray).index(4));
document.write('<br/>0 is at index : ' + $(myArray).index(0));
http://jsfiddle.net/JohnNeed/WGPMa/1/
您正在不必要地使用jQuery。 –
快速查看API文檔將顯示'index()'不適用於javascript數組http://api.jquery.com/index/。在$()中包裝一個數組是非常少見的,因爲'$()'通常用於DOM – charlietfl