0
這是我的代碼:我需要驗證複選框
<script>
function validate(form) {
fail = validate_department(form);
if (fail == "") {
return true;
} else {
alert(fail);
return false;
}
}
</script>
<script>
function validate_department(form) {
if(!(form.operations.checked == true) && !(form.marketing.checked == true) && !(form.training.checked == true)){ return "You must enter at least one of the following: marketing, training, or operations.\n";
}
return "";
}
</script>
<form method="post" action="checkbox.php" onSubmit="return validate(this)">
<input type="checkbox" name="operations" value="operations" /> Operations <br>
<input type="checkbox" name="marketing" value="marketing" /> Marketing <br>
<input type="checkbox" name="training" value="training" /> Training
<input id="submit" type="submit" name="submit" value="Signup" />
</form>
如果我不檢查任何我想要得到的消息告訴我,我必須檢查的至少一個。
您的代碼正在工作。有什麼問題 – polin
檢查這個http://jsfiddle.net/TfJZM/,它的工作 – Sibu