你用 form.proid 取得的是一个控件组,就是同名的多个复选框,不能直接用 .value 的方式取值,需要每个判断是否被选中
<script type="text/javascript">function beforeSubmit(form){
var proidCheck = "0"
var proidCheck2 = "0"
for(var i=0i<form.proid.lengthi++){
if(form.proid[i].checked){
proidCheck = "1" //proid组中有选中则记录,并退出判断
break
}
}
for(var i=0i<form.pro2id.lengthi++){
if(form.pro2id[i].checked){
proidCheck2 = "1" //pro2id组中有选中则记录,并退出判断
break
}
}
if(proidCheck=='0' && proidCheck2=='0'){
alert('至少要选择一个')
return false
}
return false
}
</script>
<form action="saveorder.asp?type=add" method="post" onSubmit="return beforeSubmit(this)">
<input type="checkbox" name="proid" value="1">
<input type="checkbox" name="proid" value="2">
<input type="checkbox" name="proid" value="3">
<input type="checkbox" name="proid" value="4">
<input type="checkbox" name="proid" value="5">
<input type="checkbox" name="pro2id" value="11">
<input type="checkbox" name="pro2id" value="12">
<input type="checkbox" name="pro2id" value="13">
<input type="checkbox" name="pro2id" value="14">
<input type="checkbox" name="pro2id" value="15">
<input type="submit"/>
</form>
可以and
<span ng-if="checked &&checked2">
I'm removed when the checkbox is unchecked.
</span>
or
<span ng-if="checked || checked2">
I'm removed when the checkbox is unchecked.
</span>