我正在使用JavaScript来验证电子邮件.问题是,当电子邮件ID不匹配时,将出现一个警报按钮.一旦我点击按钮,它仍然会将我带到另一页,而不是相同的页面来更正我的邮件ID.
HTML:
<label for="department">Email ID</label>
<input type="email" size="30" name="email" id="email" required />
<label for="department">Confirm Email ID</label>
<input type="email" size="30" name="cname" id="confirm_email" required />
<input type="submit" name="submit" value="submit" class="button" onClick="validate()">
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
function validate()
{
if(document.getElementById("email").value != document.getElementById("confirm_email").value)
alert("Email do no match");
}
Run Code Online (Sandbox Code Playgroud)