我一直在努力想出这个简单的代码。我把它归结为IF Firstname为空或== 1,它将ALERT,但最终的IF语句总是响铃为真,并且不会警告false或true。有什么想法吗?
function validateForm()
{
var firstname=document.getElementById('firstname').value.trim();
var count=0;
if (firstname.length==0)
{ alert("EMPTY");
document.getElementById("err_firstname").innerHTML="<br><span class='errorbar'>*This is a required field</span>";
} else {
count++;
alert("COUNTED");
document.getElementById("err_firstname").innerHTML="";
}
if (count==1)
{
return true;
alert("true");
} else {
document.getElementById("err_allerrors").innerHTML="<br><span class='errorbar'>*There is required information missing. Please enter all required data.</span>";
return false;
alert("false");
}
//Verified
}
答案 0 :(得分:1)
在alert()
出现问题之前返回