javascript 提交后更改表单的目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5773215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:17:59  来源:igfitidea点击:

change target of form after submit

javascriptiframeattributestarget

提问by Devin

I've been working so much on this and making zero progress I'm about to freak out. Please help!

我在这方面做了很多工作,但进展为零,我快要吓坏了。请帮忙!

Below is the code.

下面是代码。

I want the TARGET attribute of the form to change from target="frame1"to target="frame2"then target="frame3"and so on, unlimited AFTER a form is submitted. The form is submitting these to iframe so the page is not refreshing after every submit.

我希望表单的 TARGET 属性在提交表单后从那时更改target="frame1"为无限制。表单将这些提交给 iframe,因此每次提交后页面都不会刷新。target="frame2"target="frame3"

Can anyone help?

任何人都可以帮忙吗?

<div id="container">
<div id="scan">
  <form method="post" id="auditRepairForm" name="auditRepairForm" action="https://example.com.com" target="changeTarget()">
    <input name="scanID" id="scanID" value="12345678" onFocus="this.value=''" />
    <input name="fromLaunchScreen" id="fromLaunchScreen" type="hidden"/>
    <input type="submit" id="SubmitForEdit" style="display:none;"/>
  </form>
</div>

<div class="outerdiv">
<iframe name="frame1" class="inneriframe"></iframe>
</div>

<div class="outerdiv">
<iframe name="frame2" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame3" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame4" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame5" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame6" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame7" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame8" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame9" class="inneriframe"></iframe>
</div>
<div class="outerdiv">
<iframe name="frame10" class="inneriframe"></iframe>
</div>

</div>

回答by Tony Hayes

How bout changing

怎么改

<input type="submit" id="SubmitForEdit" style="display:none;"/>

to:

到:

<input type="button" id="SubmitForEdit" onclick="changeformtarget();" style="display:none;"/>

and addding

并添加

<script type="text/javascript">
var count = 1;
function changeformtarget() {
     document.getElementById('auditRepairForm').target = 'frame'+count;
     count += 1;
}
</script>

回答by Itay Moav -Malimovka

If you use IFRAME and not AJAX, you need to put a small javascript code in the page you submit to, in the iframe.
That code should either directly change the attribute of the form in the parent window, or activate a function in the parent window that does that.

如果您使用 IFRAME 而不是 AJAX,则需要在您提交的页面中的 iframe 中放置一小段 javascript 代码。
该代码应该直接更改父窗口中窗体的属性,或者激活父窗口中执行此操作的函数。

回答by Halcyon

I think you'll need to use a setTimeout because there is otherwise no chance to break out of the submit event:

我认为你需要使用 setTimeout 因为否则没有机会突破提交事件:

<script type="text/javacript">
var count = 2;
function submit() {
    setTimeout(function () {
         // this will get executed AFTER the form submits
         document.getElementById("the_form").target = "frame" + count;
         count += 1; // increase the counter so next time is frame3;
    }, 1);
    return true;
}
</script>
<form id="the_form" onsubmit="return submit();" target="frame1">
..etc..
</form>