gpt4 book ai didi

javascript - 将表单发布到弹出窗口而不是父级

转载 作者:行者123 更新时间:2023-11-28 13:50:55 25 4
gpt4 key购买 nike

我想发布一个格式弹出窗口。问题是,表单成功发布,但它也在父窗口上发布。我想仅在弹出窗口中提交表单

'<input type= button value ="Submit Form" onclick="adNetworkForm()" >
<script>
function adNetworkForm(){
targetUrl = "http://somesite.com"
var myForm = document.createElement('form');
myForm.method = 'post';
//myForm.action = targetUrl;

var inpt1 = document.createElement('input');
inpt1.setAttribute('name','a');
inpt1.setAttribute('type', 'hidden')
inpt1.value = "1";

var inpt2 = document.createElement('input');
inpt2.setAttribute('name','b');
inpt2.setAttribute('type', 'hidden')
inpt2.value = 2;
myForm.appendChild(inpt1);
myForm.appendChild(inpt2);
document.body.appendChild(myForm);
myForm.submit(popitup(targetUrl));
document.body.removeChild(myForm);
}

function popitup(url) {
newwindow=window.open(url,'name','height=600,width=500');
if (window.focus) {newwindow.focus()}
return false;
}

</script>​'

JS Fiddle

最佳答案

您可以为表单分配一个 onsubmit 事件处理程序,以调用一个函数,该函数在提交表单时弹出打开一个新窗口并将表单定位到该窗口,例如:

<form action="..." method="post" onsubmit="some_popup_post(this);">
<!-- form fields etc here -->
</form>

js代码是:

function some_popup_post(form) {
window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
form.target = 'formpopup';
}

你的意思是这样的吗..

关于javascript - 将表单发布到弹出窗口而不是父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11046088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com