输入验证功能不工作
Input Validation function not working
我有一个函数来检查是否在电子邮件字段中输入任何文本,但它不工作。
我不知道我错过了什么。
这是我的表单:
<fieldset>
<legend>Contact Information</legend>
<form action="" id="contactInfo" onsubmit="checkform()">First Name:
<input type="text" name="fname" id="fname">
<br />Last Name:
<input type="text" name="lname" id="laname">
<br />Email:
<input type="text" name="email" id="email">
<br />
<button type="submit">Submit</button>
</form>
</fieldset>
这是我在一个单独的.js
文件中的函数
function checkform(form) {
if (document.form.email.value = "") {
alert("Please enter your email address.");
document.form.email.focus();
return false;
}
return true;
}
下面是一个演示。