2
我想在驗證後重定向頁面。我有ff。實例:JavaScript:驗證後如何重定向頁面
form.html:
<form method="post" action="" enctype="multipart/form-data" onsubmit="return checkform(this);">
<p><span style="width:180px">Username: </span><input type="text" name="username" id='un'></p>
<p><span style="width:180px">Password: </span><input type="password" name="password" id='pw'></p>
<input type="submit" value="SUBMIT" />
</form>
腳本:
<script type='text/javascript'>
function checkform(){
if(document.getElementById("un").value == 'jayem30' && document.getElementById("pw").value == 'jayem'){
alert("Login Successful");
window.location = "http://www.google.com/"
}else{
alert("Access denied. Valid username and password is required.");
}
}
</script>
我試過,但它不重定向到google.com。非常感謝您的幫助! :)
應該是window.location.href – 2011-05-11 04:29:58
document.location.href也可以工作 – Amareswar 2011-05-11 05:03:43
document.location不適用於所有瀏覽器。 window.location確實。 – 2011-05-11 18:10:10