我对这一切都很陌生,我真的需要帮助。我已经在这几个小时了 我有这些复选框。我使用cfoutput生成它们,并从查询中为它们分别提供SID值。
<cfoutput query="getvalues">
<div><input type="checkbox" name="chk" id=#getvalues.SID# value=#getvalues.SID# class="chkbxs">
</cfoutput>
<input type="button" name="PrintSelected" value="Print Selected" onclick="printTextArea()">
我唯一想做的就是获取这些复选框的值并将它们存储在一个数组中。 getElementsByClassName返回一个html集合。我被告知我需要循环遍历html集合,然后将值存储在一个新的数组中,这是我在下面尝试的但是这不起作用。
<script type="text/javascript">
function printTextArea() {
var myList = document.getElementsByClassName("chkbxs");
var newList = [];
for (var i = 0; i < myList.length; i++) {
newList.push(myList[i].value);
}
for (var j = 0; j < newList.length j++)
{
alert (newList[j]);
}
}
</script>
任何帮助将不胜感激。
答案 0 :(得分:2)
为什么要将数组项设置为console.log(myList[i].value);
?
console.log()
只返回undefined
。
只需将该行更改为以下内容:
newList[i] = myList[i].value;