jQuery - 仅在更改 iframe src 时第二次单击时触发
我试图在提交表单时更改 iframe 的 src 。
除非我点击提交按钮两次,否则 iframe src 不会更改。但是,如果我只是将提交按钮的输入“类型”更改为“文本”,则它会在第一次单击时起作用 - 但显然不会提交表单。
<script>
$(document).ready(function() {
$("#form1").submit(function() {
$('#upload_frame').attr('src','upload-test.php');
});
});
</script>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input id="file" type="file" name="file" />
<input name="Submit" id="submit" type="submit" value="Submit" />
<br />
<iframe id="upload_frame" name="upload_frame"> </iframe>
</form>
I'm trying to change the src of an iframe upon submitting a form.
The iframe src won't change unless I hit the submit button twice. However, if I just change the input 'type' for my submit button to 'text', it works on the first click - but obviously doesn't submit the form.
<script>
$(document).ready(function() {
$("#form1").submit(function() {
$('#upload_frame').attr('src','upload-test.php');
});
});
</script>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input id="file" type="file" name="file" />
<input name="Submit" id="submit" type="submit" value="Submit" />
<br />
<iframe id="upload_frame" name="upload_frame"> </iframe>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我弄清楚了我遇到的问题。用setTimeout函数解决了。
我使用此表单的项目可以在这里找到:
http://www .johnboy.com/php-upload-progress-bar
I figured out the issue I was having. Resolved it with the setTimeout function.
The project in which I'm using this form can be found here:
http://www.johnboy.com/php-upload-progress-bar
您可以将类型更改为
button
并执行此操作...You can change the type to
button
and do this...为什么不使用表单的 target 属性?
应该这样做..
并且您不需要诉诸 jQuery 来获得浏览器的标准和支持的功能..
Why don't you use the target attribute of the form ?
should do it ..
And you would not need to resort to jQuery for standard and supported functionality of the browser..