我想在验证后重定向一个页面。我有 ff。示例:
表单.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。非常感谢您的帮助! :)
最佳答案
尝试将重定向置于超时状态。像魅力一样工作
setTimeout(function() {window.location = "http://www.google.com/" });
顺便说一下,而不是
onsubmit="return checkform(this);"
使用
onsubmit="return(checkform())"
因为 IE 不喜欢省略 ( 和 )。
关于JavaScript:如何在验证后重定向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5958936/