假设您的网页上有两个来自不同位置的内容。但您想一键提交两份表格。然后使用 -
您的 HTML:
<form id="form1"> <!-- Form 1 fields --> <input type="text" name="field1" placeholder="Field 1"> </form> <form id="form2"> <!-- Form 2 fields --> <input type="text" name="field2" placeholder="Field 2"> </form>
JS:
window.addEventListener('load', function() { // Get form data let form1 = new FormData(document.getElementById('form1')); let form2 = new FormData(document.getElementById('form2')); // Combine both forms data into URLSearchParams let urlParams = new URLSearchParams(); form1.forEach((value, key) => { urlParams.append(key, value); }); form2.forEach((value, key) => { urlParams.append(key, value); }); // Redirect to a new URL with combined form data window.location.href = '/submit-both-forms?' + urlParams.toString(); });
这将向该位置发送一个获取请求。
以上是一键提交更多表格的详细内容。更多信息请关注PHP中文网其他相关文章!