這讓我瘋狂...... 我從「getElementsByTagName」中創建了一個數組。現在,通過使用「this」方法返回該數組的值之一的onclick,我不能使用「indexOf」來查找其索引。控制檯告訴我「arrayThumbs.indexOf不是函數」。在數組中查找indexOf值
這是代碼:
var arrayThumbs = listThumbs.getElementsByTagName("img"); //Makes the array with the img tags
for(i=0;i<maxFiles-1;i++){
arrayThumbs[i].onclick = function(){
imgSelect = this; //Returns a valid value of the array, so far so good
indexThumb = arrayThumbs.indexOf(imgSelect); //Returns an ERROR...
};
}
的非常奇怪的是,使用相同的語法在其他陣列這個工作完全...
謝謝!
節點列表是不一個數組 –
什麼對象是'arrayThumbs'實際出現在錯誤點?使用您的瀏覽器的調試器來檢查它。 – dsh
我相信'indexOf'需要一個字符串值,而'imgSelect' mayb不會返回一個字符串... http://www.w3schools.com/jsref/jsref_indexof.asp –