gpt4 book ai didi

javascript - 将 1 个表单附加到另一个表单 - 然后提交

转载 作者:行者123 更新时间:2023-12-02 17:24:11 25 4
gpt4 key购买 nike

我有 2 个表单,1 个在我的内容中,1 个在我网站的侧边栏中。我通过 $_GET 提交它们,但我想在任何选择发生更改时提交表单。由于它们位于 2 个不同的位置并包含在 2 个单独的表单标签中,因此我需要将 #form1 附加到 #form2,然后提交 #form2。我已经查看了SO问题,所有内容都涉及 :inputclone() 但根据文档 clone() 不起作用与选择框。内容如下:.clone() Documentation

Note: For performance reasons, the dynamic state of certain form elements (e.g., user data typed into textarea and user selections made to a select) is not copied to the cloned elements. When cloning input elements, the dynamic state of the element (e.g., user data typed into text inputs and user selections made to a checkbox) is retained in the cloned elements.

那么如何将 select 表单附加到单独的表单中?

这是我迄今为止尝试过的:

jQuery('#form1 select, #form2 select').change(function(){

// Tried this
jQuery('#form1 select[name="select_name"]').append('#form2');

// Tried this before the research
jQuery('#form1 select').clone().hide().append('#form2');

// Form submission works without the above code
jQuery('#form2').submit();
});

以上方法均无效,我的控制台中也没有出现任何错误。最坏的情况是,我可以循环遍历并将值附加为隐藏输入,但我希望避免这种情况。

最佳答案

在你的第一次尝试

jQuery('#form1 select[name="select_name"]').append('#form2');

将尝试附加#form2#form1 select[name="select_name"]

想一想...如何将表单附加到选择元素?

如果您的目的是将选择选项从 form1 附加到 form2,那么您只需切换这些语句即可。

jQuery('#form2').append('#form1 select[name="select_name"]');这将附加 select选项来自 form1form2

关于javascript - 将 1 个表单附加到另一个表单 - 然后提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23639859/

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