我无法理解......
标记:
<form>
<fieldset><p>
<label>Username: <input type="text" name="user" id="user" /></label></p><br /><p>
<label>Password: <input type="password" name="passw" id ="passw" /></label></p>
<label><input type="submit" value="Log in" name="submitBUT" style="width: 65px; height: 25px; background-color: green; color: white; font-weight: bold;" id="submitBUT" /><div id="helllo"></div></label>
</fieldset>
</form>
代码:
var subBut = document.getElementById('submitBUT');
var users = ['hithere', 'Peter112', 'Geksj', 'lOsja', 'fInduS', '323DssaAA', 'f1fsus'];
var passes = ['mllesl', 'Petboy', 'Heneeesh', 'Olga', '234dasdf77/', 'minls', 'ew832ja'];
var output = [];
function submi(u, p) {
for (var i = 0; i < users.length; i++) {
if (users[i] == u) {
output.push(i);
}
}
for (var o = 0; o < output.length; o++) {
if (passes[output[o]] == p) {
return p + ' was a correct password.';
}
}
return 'Error, please try again';
}
subBut.onclick = (document.getElementById('helllo').innerHTML=(submi(document.getElementById('user').value, document.getElementById('passw').value)));
现场代码; http://jsfiddle.net/w87MS/
是的,我知道你不会在源代码中存储密码:D,它只是“fur t3h lulz”
答案 0 :(得分:6)
我必须同意上面的评论,不确定你在做什么,但问题是submit
处理程序是函数而不是字符串< / em>你要分配,这个:
subBut.onclick = (document.getElementById('helllo').innerHTML=(submi(document.getElementById('user').value, document.getElementById('passw').value)));
应该是:
subBut.onclick = function() {
document.getElementById('helllo').innerHTML=
submi(document.getElementById('user').value, document.getElementById('passw').value);
return false; //for testing, prevent form submission
};