所以我有这个简单的代码:令人难以置信的简单密码系统不工作
<!DOCTYPE html>
<html>
<head>
<title>SuM BUTtonsS DOe</title>
<link rel="stylesheet" href="buttons.css"/>
</head>
<body>
<p>Please enter the password</p>
<form id="enter" onSubmit="javascript:passCheck()">
<input id="password" type="password" placeholder="Password">
</form>
<script type="text/javascript">
var input = document.getElementById('password');
function passCheck() {
if (input == 'herro') {
window.alert("IT WORKS!!");
}
else {
window.alert("darn");
}
}
</script>
</body>
</html>
应该不会太难吧?问题是这是行不通的...
我查过的每一处似乎都说你唯一要做的就是getElementById,那会给你文本字段的内容。但是,我只是不断收到“补偿”警报。有任何想法吗?我知道函数被调用...也许输入必须在函数中?
这是不能接受的宣誓左右。我已经删除了你的问题的宣誓。 – 2015-04-03 16:38:50
'onXyz'属性包含JavaScript代码,而不是URL。没有必要使用'javascript:'伪协议(它工作的唯一原因就是它看起来像标签语句的有效JavaScript语法)。 – 2015-04-03 16:41:41