我在代码中使用了 window.location 来查看如果我正确登录,它将带我到主页,它显示警报并正确显示“密码”,但它不会引导我到新页面
我已经尝试查看此论坛和 YouTube
<button onclick="check(this.form)"> Login </button>
<script>
function check(form) {
if(form.psw.value == "password")
{
home = true;
if(home == true) {
window.location = "destination.html";
}
alert(form.psw.value);
}else {
alert("Wrong Password. Try again or click Forgot Password to reset it.")
}
}
预期结果是我被定向到destination.html页面
实际结果是我停留在我的页面上并带有警报“密码”
最佳答案
我认为问题是您试图同时做两件事,显示警报并重定向到“destination.html”。我相信发生的事情是......在重定向完成之前显示警报,这会阻止重定向操作。
关于javascript - 使用 window.location 使用 javascript 和 html 传输网页时,我做错了什么吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56086350/