1.表单里有n个checkbox 的时候 如:
<input type="checkbox" id="cashbagSaveYN" name="cashbagSaveYN" value="" />
<input type="checkbox" id="cashbagSaveYN" name="cashbagSaveYN" value="" />
<input type="checkbox" id="cashbagSaveYN" name="cashbagSaveYN" value="" />
function ifChecked()
{
var a = document.getElementsByName("cashbagSaveYN");
var n = a.length;
var k = 0;
for (var i=0; i<n; i++){
if(a[i].checked){
k = 1;
}
}
if(k==0){
alert("请选中Checkbox!");
return;
}
}
2.只有一个的时候,这时候就非常简单了 如:
<input name="Notice" type="checkbox" checked="checked" />
var checkForm = document.check_form; function goApply() {
if(checkForm.Notice.checked) {
...
}else {
alert("请选中Checkbox!");
}
}