快速验证所有复选框是否未选中的方法? [英] Fast way to validate if all checkboxes are un-selected?
问题描述
如果所有复选框都被取消选择,是否有快速的方法或函数能够告诉我真假?没有通过数组? (使用JS和HTML)
我的所有复选框都有相同的名称...
$ pre> < form action =/ cgi-bin / Lib.exemethod = POST name =checksID =Form2>
< input type = checkbox name =usvalue =JoeID =Checkbox1>
< input type = checkbox name =usvalue =DanID =Checkbox2>
< input type = checkbox name =usvalue =SalID =Checkbox3>
< / form>
您必须遍历它们。即使像jQuery这样的库也会循环使用它们,只是隐藏它。
);var inputs = form.getElementsByTagName('input');
var is_checked = false;
for(var x = 0; x< inputs.length; x ++){
if(inputs [x] .type =='checkbox'&& inputs [x] .name == 'us'){
is_checked = inputs [x] .checked;
if(is_checked)break;
}
}
// is_checked在此时将被检查为布尔值'true'。
Is there a quick way or function that would tell me true/false if all check boxes are deselected? Without going through array? (with JS and HTML)
All my check boxes have the same name...
<form action="/cgi-bin/Lib.exe" method=POST name="checks" ID="Form2">
<input type=checkbox name="us" value="Joe" ID="Checkbox1">
<input type=checkbox name="us" value="Dan" ID="Checkbox2">
<input type=checkbox name="us" value="Sal" ID="Checkbox3">
</form>
You have to loop through them. Even a library like jQuery will loop through them, just hide it from you.
var form = document.getElementById('Form2');
var inputs = form.getElementsByTagName('input');
var is_checked = false;
for(var x = 0; x < inputs.length; x++) {
if(inputs[x].type == 'checkbox' && inputs[x].name == 'us') {
is_checked = inputs[x].checked;
if(is_checked) break;
}
}
// is_checked will be boolean 'true' if any are checked at this point.
这篇关于快速验证所有复选框是否未选中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!