function piliang() {
var ids = "";
var num = document.getElementsByName("check");
for (var i = 0; 1 < num.length; i++) {
if (num.item(i).checked) {
ids = ids + num.item(i).value + ",";
}
alert(ids);
}
成功运行
function piliang() {
var ids = "";
var num = document.getElementsByName("check");
for (var i = 0; 1 < num.length; i++) {
if (num.item(i).checked) {
ids = ids + num.item(i).value + ",";
}
}
这会发出以下错误:
&#34;无法阅读财产&#39;已检查&#39; of null&#34;
第一个代码也有此错误,但可以成功运行
我的英语不好,请尝试用代码解释一下,非常感谢
答案 0 :(得分:1)
修正了for
循环
function piliang() {
var ids = "";
var num = document.getElementsByName("check");
for (var i = 0; 1 < num.length; i++) { //use i instead of 1
if (num.item(i).checked) {
ids = ids + num.item(i).value + ",";
}
}