我正在修改一個php登錄表單,並在其中添加了javascript check form函數。我希望當用戶勾選複選框時,表單爲真,當複選框爲空時,表單將變爲false。代碼是這樣的: -複選框值在檢查窗體中,php
//the javascript
function check_sli(form,mark,edit){
if(mark==1 || mark=="all"){
if(form.terms.value==""){
sli_check_terms.innerHTML="Please read the terms and conditions first!";
sli_check_terms.style.height="auto";
return false;
}else{
sli_check_terms.innerHTML="";
sli_check_terms.style.display = "none";
}
}
}
//the form
<form name="form_sli" id = "form_sli" ACTION="<?php echo $loginFormAction1; ?>" METHOD="POST" onSubmit="return check_sli(form_sli,'all')">
<input type="text" name="login"/><br>
<input type="password" name="password"/><br>
<input name="terms" type="checkbox" id="terms" checked="checked" onBlur="check_sli(form_sli,1)">I have read the terms and conditions<br><div id="sli_check_terms" class="right"></div>
<input type="submit" name="button" id="button" value="Login" />
</form>
上述代碼的工作正常的文本框,諸如當文本字段是空的,的innerHTML彈出。但是,當使用複選框,我不知道檢查和未檢查的值,是1比0還是!==「」vs ==「」?並且我應該使用onBlur還是onSubmit?
它應該如何修改腳本以使其對複選框起作用?非常感謝!