Javascript和只有一个复选框 - 未定义 [英] Javascript and only one Checkbox - undefined
本文介绍了Javascript和只有一个复选框 - 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for (i = 0; i < document.checks.user.length; i++) //for all check boxes
{
if (document.checks.user[i].checked == true )
{
document.checks.submit();
return 0;
}
}
<body>
<form action="" method=POST name="checks" ID="Form2">
I have a bike:
<input type="checkbox" name="user" value="Bike" ID="Checkbox1">
<br>
<br>
</form>
<input type="button" value="Delete"
class="btn" onclick="sub_delete()"
onmouseover="hov(this, 'btn btnhov')" onmouseout="hov(this, 'btn')"
id="Button1" name="Button1"
/>
</body>
你可能已经知道当只有一个复选框时document.checks.user.length =未定义。什么是最有效的方式,以确保当只有一个复选框,它将被删除。我想只是想把它添加为一个单独的if语句之前的if语句这里.....任何suggesstions。
as you probably already know when there is only one check box left document.checks.user.length = undefined. Whats the most efficient way to make sure that when there is only one check box, it will be deleted. I was thinking just thinking to add it as a seperate if statement before the if statement here.....any suggesstions.
谢谢。
推荐答案
使用循环控制变量,如果length未定义,则将其设置为1 ...
Use a loop control variable, and set it to 1 if length is undefined...
var len = document.checks.user.length;
if(len == undefined) len = 1;
for (i = 0; i < len; i++) //for all check boxes
最好的问候...
这篇关于Javascript和只有一个复选框 - 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文