gpt4 book ai didi

javascript - 提交表单数据并在新的弹出窗口中显示表单数据

转载 作者:行者123 更新时间:2023-12-02 23:31:20 25 4
gpt4 key购买 nike

我有一个如下所示的表格

<html>

<form action="test.html" method="post" onsubmit="target_popup(this)">
<select id="types">
<option value="a" >A</option>
<option value="b" >B</option>
</select>

<select id="types1">
<option value="a" >A</option>
<option value="b" >B</option>
</select>

<input type="submit" value="Submit">

</form>
<script>
function target_popup(form) {
var out1 = document.getElementById('types').value;
var out2 = document.getElementById('types1').value;
window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
form.target = 'formpopup';
}
</script>
</html>

提交后,会打开一个新窗口,当前是一个空白的 html。我想将表单数据写入此 html。

如何仅使用 javascript 和 html 来做到这一点?

最佳答案

将新打开的窗口的引用存储在变量中,然后将选定的值分配给其document.body.textContent

<form action="test.html" method="post" onsubmit="target_popup(event)">
<select id="types">
<option value="a" >A</option>
<option value="b" >B</option>
</select>

<select id="types1">
<option value="a" >A</option>
<option value="b" >B</option>
</select>
<input type="submit" value="Submit">
</form>

function target_popup(e) {
e.preventDefault();
var out1 = document.getElementById('types').value;
var out2 = document.getElementById('types1').value;
const wdw = window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
wdw.document.body.textContent = out1 + ' ' + out2;
}

关于javascript - 提交表单数据并在新的弹出窗口中显示表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56488271/

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