【发布时间】:2016-01-19 15:21:36
【问题描述】:
我不知道如何将以下条件反应链接到 passid 表单输入 ID:
我不知道将 document.querySelector() 方法放在哪里,以便索引的 contion-reactions 将与之关联。
代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Password - form</title>
</head>
<body>
<form>
<label>Password</label>
<input type="password" id="passid" />
<br>
<input type="submit" value="Sign In" />
</form>
<script>
function passType() {
var password = ["p1", "p2", "p3", "p4", "p5"];
if (password.indexOf > -1) {
alert("That's great! Thank you!");
} else {
alert("Wrong, try again");
}
if (password.indexOf > -1) {
alert("It's wrong, you have one more try...");
} else {
alert("Get out now!");
window.close();
}
}
passType();
</script>
</body>
</html>
这应该怎么做?
【问题讨论】:
-
password.indexOf想做什么? (它不会按照你的方式工作。) -
之前有一个“提示”,但我现在添加了一个表单并尝试通过 querySelector 将脚本与表单相关联。我是 JS 新手 --- 我认为 password(var).indexOf 只是指变量。
-
你检查过 Barmar 的回答吗?
标签: javascript html methods conditional-statements