我正在使用以下代码的变体。当我按下回车键时,它会刷新整个网页,而不是提交表单。我尝试搜索,但我对编码一无所知,所以其他答案都没有帮助我,因为它们不是我的代码特有的。在此先感谢,非常感谢您的帮助!
<html>
<head>
<head>
<style>
.button {
background-color: blue; /* Green */
border: 1;
color: white;
padding: 8px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
input {
width: 200px;
height: 30px;
background-color : #d1d1d1;
border-style:groove;
}
</style>
</head>
<body>
<form name="login" method=POST>
<center>
<strong>Password:<strong>
<input type="password" name="pswrd" onkeydown = "if (event.keyCode == 13)
document.getElementById('pwsubmit').click()" />
<button class="button" id="pwsubmit" type="button"
onclick="check(this.form)" value="Login"/>Submit</button></center>
</form>
<script language="javascript">
function checkentry(e)
{
document.getElementById("pswrd")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode == 13) {
document.getElementById("id_of_button").click();
}
});
}
function check(form)
{
// The list below MUST contain all valid passwords
if (['laura', 'molly', 'katie', 'chris'].indexOf(form.pswrd.value) >= 0) {
// Go to different websites/weebly pages based on the entered password
switch(form.pswrd.value) {
case "laura":
window.open('http://www.bk.com','_self');
break;
case "molly":
window.open('http://www.mcdonalds.com','_self');
break;
case "katie":
window.open('https://www.supermacs.ie/','_self');
break;
case "chris":
window.open('https://www.kfc.ie/','_self');
break;
}
}
// Show following message if invalid password entered
else {alert("Invalid password entered!!!")}
}
</script>
</body>