我正在用 JavaScript 编写生日验证表单,但它不起作用。你能帮忙找出哪一部分是错的吗?如何解决?
JavaScript
function onFormSubmit(form_element) {
var slashcount = 0;
if ((form_element.birthday.value =="")||(form_element.birthday.value ==null))
{
alert("This field is required. Please enter date mm/dd/yyyy!");
false;
}
for (var i=0; i < birthday.length; i++)
{
temp = "" + birthday.substring(i, i+1);
if (temp == "/")
{
slashcount++;
}
if (valid.indexOf(temp) == "-1")
{
alert("error1.");
false;
}
if (slashcount != 2)
{
alert("error2");
false;
}
if((birthday.charAt(2)!= '/')||( birthday.charAt(5) != '/'))
{
alert("error3");
false;
}
}
return true;
}
HTML
<form onsubmit="return onFormSubmit(this)">
Birthday:<input type="text" name="birthday" /><br />
<input type="submit" value="submit" />
</form>