我在 javascript popUp 中有一个小函数,我想知道 getElementByClassName 函数是否返回一个包含该类的所有元素的数组,而不是为什么当我提醒它说对象 Html 输入元素时,尽管我的表单编号字段中有什么(空白空间或一些数字)。那么我如何从该数组中获取值。
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>