gpt4 book ai didi

javascript - 从不同字段以不同形式向服务器提交数据

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

在jquery中,当你想提交表单时

$(document).ready(function(){
$("form").submit(function(){
alert("Submitted");
});
});

我的问题是:我有一堆字段(它们的形式不同,或者根本不具有任何形式)。当我按下发送按钮时,jquery 将获取所有这些字段的值并将其发送到服务器(作为发送表单)。

我不知道如何在 jquery 中做到这一点。请告诉我

谢谢:)

最佳答案

所以您想发送页面中所有表单中的所有值以及一些不以任何表单形式的值,并以新表单发送所有值,对吗?

  var theForm = $('<form></form>');

$('form').find('input, textarea, select').each(function() {
theForm.append('<input type="hidden" value='+ $(this).val() +' id='+$(this).attr('id') +' name ='+$(this).attr('id') +'>')
});

$('#input1, .moreinputs').each(function() {
theForm.append('<input type="hidden" value='+ $(this).val() +' id='+$(this).attr('id') +' name ='+$(this).attr('id') +'>')
});

theForm.submit();

这样您就可以创建一个包含您需要的所有值的新表单。

关于javascript - 从不同字段以不同形式向服务器提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29659561/

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