所以我有一个文本字段,用户必须在其中输入密码才能下载 PDF 文件。如果密码正确,它会将用户重定向到 PDF 文件 url,如果密码错误,它会将用户重定向到另一个名为不正确 (incorrect.html) 的页面。
一切正常。唯一的问题是当您按下 Enter 键时,它不会重定向页面。它仅在您单击“提交”按钮时有效。
有没有办法来解决这个问题?
非常感谢!
输入文本字段和提交按钮
<form name="login">
<input class="gen-label" type="text" name="pass" size="17" onKeyDown="if(event.keyCode==13) event.keyCode=9;">
<input class="button submit" type="button" value="Submit" onClick="TheLogin(this.form)">
</form>
Javascript
<script>
function TheLogin() {
var password = 'Pass1';
if (this.document.login.pass.value == password) {
top.location.href="file_to_download.pdf";
}
else {
location.href="incorrect.html";
}
}
</script>