我有最烦人的问题!我正在使用一个易于使用的密码脚本:
var count = 2;
function validate() {
var un = document.myform.username.value;
var pw = document.myform.pword.value;
var valid = false;
var unArray = ["Natalie"];
var pwArray = ["0123456"];
for (var i = 0; i < unArray.length; i++) {
if ((un == unArray[i]) && (pw == pwArray[i])) {
valid = true;
break;
}
}
if (valid) {
window.location = "hello.html";
} else {
alert("ERRR! Wrong!");
document.myform.username.value = "";
document.myform.pword.value = "";
document.myform.username.disabled = true;
document.myform.pword.disabled = true;
return false;
}
}
现在,我为这个脚本做了一个表格:
<form method="POST" onsubmit="return validate()" name="myform">
<input type="text" value="Natalie" name="username" style="width:0px;height:0px;border:0px solid;background:rgba(00,00,00,0);">
<input type="text" name="pword" style="width:150px;border:1px solid #fff;font-family:roboto;font-size:12px;padding:1% 12%;text-align:center;letter-spacing:4px;font-weight:900;margin:2%;" value="Ex: 354627" onfocus="if (this.value == 'Ex: 354627') {this.value=''}">
<br>
<input name="submit" type="submit" value="Check In" onclick= " validate()">
</form>
一切正常,除了输入密码并按回车键!
为什么会这样,我该如何解决?我花时间把它全部放在一个 JSFiddle 中!