我对制作网站还是比较陌生的,但是,我尝试使用HTML / Javascript,以便用户可以使用ENTER键或“提交”按钮输入密码,无论用户选择哪个。当我仅打印诸如“ Welcome!”之类的消息时,我的代码即可工作。但是当我要将它们重定向到另一个页面(如“ intro.html”)时,多数民众赞成在它停止工作时。我已附上我的代码。我了解event.keyCode可能不是javascript,可能是jquery?如果是这样,请让我知道如何将jquery实现为html或大家可能有的任何其他想法:)非常感谢!
登录
<script language = "JavaScript">
function showPass(form){
var pass = form.pwd.value;
var pass1 = "tanwebdesign"
var pass2 = event.keyCode || event.which;
if(pass == pass1 || ((pass == pass1) && pass2 == 13))
{
window.location.replace("intro.html");
}
else{
window.open = "LogIn.html"
}
}
</script>
<form>
Password: <input type = "password" name = "pwd" />
<input type = "submit" style = "display: none" onclick = "showPass(form)" />
<input type = "button" value = "Log In" onclick = "showPass(form)" />
</form>
答案 0 :(得分:0)
这是怎么做的
input
即可执行相同的操作e.preventDefault()
来阻止表单的默认重定向。请参见function showPass(form , e)
,在html onSubmit = "showPass(this , event)"
中,您可以将onSubmit
用于表单而不是onClick
提交输入ENTER
键,它将自动与表单一起使用window.location.href = 'https://www.google.com'
function showPass(form , e){
e.preventDefault();
var pass = form.pwd.value;
var pass1 = "tanwebdesign";
alert(pass);
if(pass == pass1 || pass == pass1)
{
//window.location.replace("intro.html");
}
else{
//window.open = "LogIn.html"
}
}
<form onSubmit = "showPass(this , event)">
Password:
<input type = "password" name = "pwd" />
<input type = "submit" value = "Log In" />
</form>