如标题所述,我如何检查给定的用户名和密码是否是用户输入的内容并提示成功或失败?警报不再弹出。我将 js 脚本嵌入到 html 文件中。
这是脚本:
function login() {
var username = ["user1", "user2", "user3"];
var password = ["1", "2", "3"];
var idInput = document.getElementById("id");
var pwInput = document.getElementById("pw");
if (username[0] == idInput) {
if (password[0] == pwInput) {
alert("login success!");
} else if (username[1] == idInput) {
if (password[1] == pwInput) {
alert("login success!");
} else if (username[2] == idInput) {
if (password[2] == pwInput) {
alert("login success!");
} else {
alert("please try again");
}
} else {
alert ("please try again");
}
} else {
alert ("please try again");
}
}
}
这是通过 html 和按钮输入的正文:
<table>
<tr>
<td>Login Id:</td>
<th>
<INPUT type="text" Size="40" Maxlength="35" id="id" placeholder="Your Username Here">
</th>
</tr>
<tr>
<td>Password:</td>
<th>
<INPUT type="text" Size="40" Maxlength="40" id="pw" placeholder="Your Password Here">
</th>
</tr>
</table>
<button onclick="login()">Login</button>
喵喔喔
跃然一笑
拉丁的传说
相关分类