我在javascript彈出窗口中有一個小函數,我想知道如果getElementByClassName函數返回的所有元素與該類的數組比爲什麼當我警告它說對象Html輸入元素儘管我有什麼在我的表單編號字段(空格或一些數字)內。那麼我如何從該數組中獲取值。javascript getElementsByClassName值錯誤
var arr = document.getElementsByClassName('num');
function popUp(){
for(var i = 0;i < arr.length;i++){
alert(arr[i]);
}
}
下面是HTML:
<form id = "matrix">
<input type = "number" class = "num" />
<input type = "number" class = "num" />
<input type = "number" class = "num" />
<input type = "number" class = "num" />
<input type = "button" value = "count" id = "count" onclick = "popUp()"/>
</form>
</div>
它返回_elements_的陣列狀物體(實際上的HTMLCollection) - 不_values_。 – nnnnnn 2013-04-21 12:01:07