表单提交后的javascript代码
我在网页上测试了以下 JavaScript 代码。
<form method=POST id="someform" action="http://localhost/somepage.php" >
<input type=hidden name=stuff value="value">
</form>
<script>
document.forms['someform'].submit();
window.location="http://google.com";
</script>
提交表单后,窗口成功重定向到 google。我不明白为什么。控制权不是转移到somepage.php了吗?为什么 window.location ... 仍然被执行。
I tested the following javascript code on a webpage.
<form method=POST id="someform" action="http://localhost/somepage.php" >
<input type=hidden name=stuff value="value">
</form>
<script>
document.forms['someform'].submit();
window.location="http://google.com";
</script>
The window successfully redirects to google after the form is submitted. I don't understand why. Isn't the control transfered to somepage.php? why is the window.location ... still executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所调用的所有内容都会在页面不消失的情况下执行。
submit()
调用不会阻止执行,它会立即返回。Everything that is called is executed while the page doesn't disappear. The
submit()
call doesn't block the execution, it returns immediately.