gpt4 book ai didi

javascript - 按 Enter 提交密码表单,如果不正确则有效,如果正确则失败

转载 作者:行者123 更新时间:2023-11-28 10:40:22 25 4
gpt4 key购买 nike

当密码不正确时,此密码表单的行为符合预期,但当密码正确时,按键盘上的 ENTER 键不会提交该表单。

这是 JavaScript:

function TheLogin() {
var password = 'beyond';
if (this.document.login.pass.value == password) {
top.location.href = "streettherapy224984.html";
} else {
window.alert("INCORRECT PASSWORD. ACCESS DENIED.");
}
}

function forceLower(strInput) {
strInput.value = strInput.value.toLowerCase();
}
<form name="login" style="margin: 5px 0px 0px 0px;">
<input class="main" type="text" name="pass" size="64" onkeydown="if(event.keyCode==13) document.getElementById('codebtn').click()" style="width: 230px;" onkeyup="return forceLower(this);"><br>
<div id="spacer20"></div>
<input class="main" type="button" id="codebtn" value="Submit" onclick="javascript:TheLogin(this.form)">
</form>

我完全迷失了,所以非常感谢任何帮助解决这个问题的人!

最佳答案

您在这里遇到多个问题:

按原样修复

1. <form ... onsubmit="TheLogin()">
2. <input ... type="submit" id="codebtn"...>

去掉“pass”输入上的任何按键,输入“submit”会触发“onsubmit”函数,这样登录

function TheLogin() {
var password = 'beyond';
if (this.document.login.pass.value == password) {
window.location.href = "http://www.tanatu.com/streettherapy224984.html";
} else {
alert("INCORRECT PASSWORD. ACCESS DENIED.");
}
}

function forceLower(strInput) {
strInput.value = strInput.value.toLowerCase();
}
form {margin: 5px 0px 0px 0px;}
#pass {width: 230px;}
<form name="login" onsubmit="TheLogin()">
<input class="main" type="text" id="pass" onkeyup="return forceLower(this);">
<hr>
<input class="main" type="submit" id="codebtn" value="Submit">
</form>

还有

If you want to simulate clicking on a link, use location.href = URL

If you want to simulate an HTTP redirect, use location.replace(URL)

关于javascript - 按 Enter 提交密码表单,如果不正确则有效,如果正确则失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52649428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com