从检查密码重定向



我有一个非常基本的网站,有一个快速简单的方法来快速发送到页面,但我不知道如何做到这一点。

所以我有:

<form class="passform" action="" onsubmit="return passcheck()">
password: <input type="password" required id="pass1">
<input type="submit">
</form>

在HTML中使用js

var password = "%Password%";
const submit = document.getElementById("pass1")

function passcheck () {
if(submit.value != password) {
alert('Wrong Password, Try Again.')
return false
}
}  
function passcheck () {
if(submit.value == password) {

alert('Correct Pasword, lets go')
window.location.href="/pic/index.html";
}}

您不需要返回任何内容,只需在相等时重定向,如果不相等则打印消息,如:

var password = "%Password%";
const submit = document.getElementById("pass1");
function passcheck() {
if (submit.value == password) {
alert('Correct Pasword, lets go')
window.location.href = "/pic/index.html";
} else {
alert('Wrong Password, Try Again.')
}
}
<form class="passform" action="" onsubmit="event.preventDefault();passcheck()">
password: <input type="password" required id="pass1">
<input type="submit">
</form>

我简单地添加event.preventDefault()(我用EventListener更改内联方法(以防止提交并检查if密码是否相等继续else打印消息

真正的问题是,你确定这个方法吗?不安全。

最新更新