我正在用 JavaScript 编写 CAPTCHA 代码,我正在尝试验证联系表单是否正常工作。我快到了,在输入验证码文本字段之前不会提交表单,但问题是当我正确输入验证码时仍然收到错误消息。
<script>
function ValidateContactForm()
{
var name = document.ContactForm.name;
var phone = document.ContactForm.phone;
var code = document.ContactForm.code;
if (name.value == "")
{
window.alert("Please enter your name.");
name.focus();
return false;
}
if (phone.value == "")
{
window.alert("Please enter a valid phone number..");
phone.focus();
return false;
}
if (code.value == "")
{
window.alert("Please enter the code as displayed on screen.");
code.focus();
return false;
}
else if (code.value != "")
{
window.alert("Your code does not match. Please try again.");
code.focus();
return false;
}
else {
return true;
}
return true;
}
</script>
任何帮助将不胜感激。谢谢。