我一直在尝试使用 HTML 和 Javascript 进行网站登录,除了一个问题外它工作正常。首次登录信息登录,但弹出else消息显示!我该如何解决?
function Login(form)
{
username = new Array("alex364981");
password = new Array("Codylewis");
page = "user2" + ".html";
if (form.username.value == username[0] && form.password.value == password[0]
|| form.username.value == username[1] && form.password.value == password[1]
|| form.username.value == username[2] && form.password.value == password[2]
|| form.username.value == username[3] && form.password.value == password[3]
|| form.username.value == username[4] && form.password.value == password[4]
|| form.username.value == username[5] && form.password.value == password[5]
|| form.username.value == username[6] && form.password.value == password[6]
|| form.username.value == username[7] && form.password.value == password[7]
|| form.username.value == username[8] && form.password.value == password[8]
|| form.username.value == username[9] && form.password.value == password[9])
{
self.location.href = page;
}
username = new Array("test");
password = new Array("this");
page = "user1" + ".html";
if (form.username.value == username[0] && form.password.value == password[0]
|| form.username.value == username[1] && form.password.value == password[1]
|| form.username.value == username[2] && form.password.value == password[2]
|| form.username.value == username[3] && form.password.value == password[3]
|| form.username.value == username[4] && form.password.value == password[4]
|| form.username.value == username[5] && form.password.value == password[5]
|| form.username.value == username[6] && form.password.value == password[6]
|| form.username.value == username[7] && form.password.value == password[7]
|| form.username.value == username[8] && form.password.value == password[8]
|| form.username.value == username[9] && form.password.value == password[9])
{
self.location.href = page;
}
else
{
alert("Either the Username or Password is Wrong.\nPlease try again.");
form.username.focus();
}
return true;
}