它不返回 false 并且不显示错误。见 jfiddle http://jsfiddle.net/paYap/2/
我的JavaScipt:
function validateForm() {
var error = "";
var x=document.getElementById('fname').value;
var y=document.getElementById('lname').value;
/*
Additional variable defined here, commented out for debugging
*/
if ((x==null || x=="") || (y==null || y==""))
{
error += "-First and last name required. <br />";
}
/*
There were additional statements here, commented out for debugging
*/
if (error != ""){
alert(error);
//document.getElementById('error').innerHTML = "Error: " + error;
return false;
}
}
我也附上onsubmit="return validateForm()"
了表格。
有人可以帮我看看并告诉我是否遗漏了什么吗?