javascript 如何在按钮onclick动作上的新弹出窗口中提交表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5700222/
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:03:39  来源:igfitidea点击:

How to submit form in new pop up on button onclick action

javascriptjqueryhtml

提问by RandomQuestion

I want to have a form and need to submit it to a url in a new pop up window on button onclick action. I want something like this.

我想要一个表单,并且需要在按钮 onclick 操作的新弹出窗口中将其提交到一个 url。我想要这样的东西。

<form id = "test" name = "test" action = "preview.jsp">
    Email : <input type = "text" name = "email"/>
    <button id = "submitButton" onclick = "submitFormInPopUp()"/>
</form> 

So how to write this function submitFormInPopUp() which posts to action url in a new pop up page.

那么如何编写这个函数 submitFormInPopUp() 在一个新的弹出页面中发布到 action url。

Thanks

谢谢

Jitendra

吉腾德拉

回答by Anand Thangappan

Use this:

用这个:

function submitFormInPopUp() 
{
 window.open('','Prvwindow','location=no,status=no,toolbar=no,scrollbars=yes,width=730,height=500');

 document.test.action = "preview.jsp"
 document.test.target = "Prvwindow"
 document.test.submit(); 
}

i hope its help to u

我希望它对你有帮助

回答by wong2

function submitFormInPopUp(){
    var url = "preview.jsp?email=" + document.getElementsByTagName('input')[0].value;
    window.open(url);
}

回答by Franti?ek ?ia?ik

Maybe you could use the targetattribute?

也许您可以使用该target属性?

http://www.w3schools.com/TAGS/att_form_target.asp

http://www.w3schools.com/TAGS/att_form_target.asp

Change the button type to submitand specify target, you don't need any javascript.

将按钮类型更改为submit并指定target,您不需要任何 javascript。

<form id="test" name="test" action="preview.jsp" target="_blank">
    Email : <input type = "text" name = "email"/>
    <input type="submit" value="Submit" id="submitButton" />
</form> 

Be aware though it's deprecated and not allowed in Strict.

请注意,尽管它已被弃用并且在 Strict 中不允许使用。