<script language="javascript">
function check(form)
{
if(form.userid.value == "username1" && form.pswrd.value == "password1" || form.userid.value == "username2" && form.pswrd.value == "password2" || form.userid.value == "username3" && form.pswrd.value == "password3")
{
window.open('http://www.youtube.com')
}
else
{
alert("hello rising field student, your password or username is wrong!")
}
}
</script>
以下是我用javascript编写的代码,成功登录后实际上需要用户访问www.youtube.com。我想要一种情况,每个用户都会被分配一个特定的URL,所以当他们登录时,他们将被带到该URL。感谢在这种情况下非常有帮助的任何人。
答案 0 :(得分:0)
对于特定用户应传递给if
的每个网址,您可以使用window.open()
条件,并使用设置为布尔true
或false
的变量检查if
元素值的form
条件评估为true
<script language="javascript">
function check(form) {
var username = form.userid.value;
var password = form.pswrd.value;
var validUser = false;
if (username == "username1" && password == "password1") {
validUser = true;
window.open("/path/to/url/1")
}
if (username == "username2" && password == "password2") {
validUser = true;
window.open("/path/to/url/2")
}
if (username == "username3" && password == "password3") {
validUser = true;
window.open("/path/to/url/3")
}
if (!validUser)
alert("hello rising field student, your password or username is wrong!")
}
}
</script>