Javascript 密码验证窗口.location.replace.
Javascript Password Verification window.location.replace
我有一个网站,我想制作一个JavaScript登录表单。
不像一个完美的用户名和密码登录,但我想建立一个密码验证登录。我希望用户在正确时重定向到私有.html当他们做错时.html重定向到错误。
这是 HTML:
<script type="text/javascript">
function checkForm() {
x = document.getElementById("holy").value
if (x == "mangos") {
alert("Right Password!");
window.location.replace("private.html");
}
else {
alert("Wrong Password!");
window.location.replace("home.html");
}
}
</script>
<center>
<form class="form-container">
<center>
<div class="form-title"><h2>Login</h2></div>
<div class="form-title">Username</div>
<input class="form-field" type="text" name="username" /><br />
<div class="form-title">Password</div>
<input class="form-field" type="password" id="holy" name="password" /><br />
<div class="submit-container">
<button onclick="checkForm()" class="submit-button">Login</button>
</div>
</center>
</form>
显然,函数中的警报部分有效,但是代码的下一部分,即 window.location.replace 根本不起作用。相反,网址变为
.com/password.html?username=asd&password=mangos
我应该怎么做/解决这个问题?
发生这种情况是因为表单正在提交,这是它的默认行为。要避免这种情况,请在 checkForm() 函数的末尾编写一个返回 false。
function checkForm() {
x = document.getElementById("holy").value
if (x == "mangos") {
alert("Right Password!");
window.location.replace("private.html");
return false;
}
else {
alert("Wrong Password!");
window.location.replace("home.html");
return false;
}
}
相关文章:
- 在AJAX中使用window.location.replace'成功'回调
- 后退按钮在 window.location.replace(href);之后失败
- 我能确定这个页面赢了吗;如果我使用`location.replace`来更改哈希,则不会重新加载
- How to do "HTML FORM action=location.replace('nextp
- window.location.replace.继续重新加载页面,如何停止
- window.location.replace或href时Web会话丢失
- “拒绝影子本机属性的权限”使用 location.replace 在 JavaScript 中重定向
- 如何使 window.location.replace 在 IE 9 中工作
- 使用 window.location.replace 但页面仍在浏览器的内存中
- JavaScript Location.replace 不起作用
- window.location.replace :权限被拒绝和未捕获的异常
- window.location.replace() 在窗体中不起作用
- Javascript 密码验证窗口.location.replace.
- 如何在window.location.replace.之后保持相同的表单
- 使用window.location.replace重定向不起作用
- window.location.replace不起作用
- window.location.replace在客户端不起作用
- 如何覆盖JavaScript中的location.assign或location.replace函数
- 如果重新加载了同一页,window.location.replace将不起作用
- location.replace(),并在返回数据时移动到新页面