所以我对JavaScript很陌生,而且我有这个表单来检查你的密码是否等于变量,但是一旦我输入了密码,密码类型,就不再说它们是相同的。
<script>
function log(f) {
if ((f.username.value == "ben")&&(f.password.value == "password")) {
alert("success");
} else {
alert("failure);
}
}
</script>
<form name = "f">
Username:
<input type="text" name = "username">
Password:
<input type = "password" name = "password">
<br>
<input type = "button" value = "Enter" onClick = "log(f)">
<br>Result:
<input type = "text" name = "result">
</form>
答案 0 :(得分:0)
您的代码运行正常。但是,此处存在语法错误:您alert("failure);
错过了"
。将其更改为alert("failure");
您可以在此处查看jsfiddle