此javascript函數在窗體中查找錯誤並將其列出。如果有錯誤,它會創建一個錯誤覆蓋複選框,以便即使出現錯誤也能提交。目前代碼不能識別複選框何時被選中。顯然,第一條if語句總是被發現是真實的。想法?複選框值在選中時不會從false更改爲true
function check1()
{
// c_ierrors is the id of the input tag inserted below within the c_erros div
if(document.getElementById("c_ierrors")==null || document.getElementById("c_ierrors").checked!="true")
{
//if javascript generated form error overide checkbox does not exist or exists but is not true then list errors and don't submit the form
//code to generate divs listing errors
//
if(error=="")
{
//submit form
return true;
}
else
{
error += "<div id=\"c_erow\"><input type=\"checkbox\" id=\"c_ierrors\" name=\"override\" value=\"y\" >Override Errors</div>" //add checkbox to submit form despite errors
document.getElementById("c_errors").innerHTML=error;
alert (document.forms["cform"]["override"].checked);
return false; //stay on page don't submit form
}
}
else
{
//if override checkbox (exists) and is true
return true;
}
}
的確是謝謝。即使經過很多次代碼,我完全錯過了。 – user2268439 2013-04-11 02:16:38