简体   繁体   English

HTML提交表单,但留在同一页面上

[英]Html submit a form, but stay on the same page

I want to create a form with HTML, that when submitting it will run a javascript function (the function itself needs to contact a local server (localhost:...)), but when inside the javascript function I use window.open(...) a new tab is opened. 我想用HTML创建一个表单,提交时将运行javascript函数(该函数本身需要联系本地服务器(localhost:...)),但是在javascript函数内部时,我使用window.open(。 ..)打开一个新标签。 I want the form to be submitted but not to change the current page, meaning to stay on the form. 我希望提交表单,但不更改当前页面,这意味着保留在表单上。 How do I do that? 我怎么做?

If you are using type="submit" but want to stay on the same page you could try changing the input type to button so that it would read... 如果您使用的是type="submit"但希望保留在同一页面上,则可以尝试将输入类型更改为button,以便其显示为...

input type="button" value="Submit" onclick="myFunction()"

and in the function call the box variables with... 然后在函数中使用...调用框变量

var name = document.formName.boxName.value;

设置表单的target

<form target="_blank" action="http://example.com">.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM