我如何合并所有表格?

时间:2013-05-24 18:43:21

标签: jquery forms submit

我想在一个新表单中发布所有表单字段,然后提交它。 我使用这段代码:

function submitAllDocumentForms() {
            var arrDocForms = document.getElementsByTagName('form');
            var formCollector = document.createElement("form");
            with(formCollector)
            {
                method = "post";
                action = "";
                name = "formCollector";
                id = "formCollector";
            }
            for(var ix=0;ix<arrDocForms.length;ix++) {
                appendFormVals2Form(arrDocForms[ix], formCollector);
            }
            document.body.appendChild(formCollector);
            formCollector.submit();

            }
        /* Function: add all elements from ``frmCollectFrom´´ and append them to ``frmCollector´´ before returning ``frmCollector´´*/
        function appendFormVals2Form(frmCollectFrom, frmCollector) {
            var frm = frmCollectFrom.elements;
            for(var ix = 0 ; ix < frm.length ; ix++)
                frmCollector.appendChild(frm[ix]);
            return frmCollector;
        }

function submitAllDocumentForms() { var arrDocForms = document.getElementsByTagName('form'); var formCollector = document.createElement("form"); with(formCollector) { method = "post"; action = ""; name = "formCollector"; id = "formCollector"; } for(var ix=0;ix<arrDocForms.length;ix++) { appendFormVals2Form(arrDocForms[ix], formCollector); } document.body.appendChild(formCollector); formCollector.submit(); } /* Function: add all elements from ``frmCollectFrom´´ and append them to ``frmCollector´´ before returning ``frmCollector´´*/ function appendFormVals2Form(frmCollectFrom, frmCollector) { var frm = frmCollectFrom.elements; for(var ix = 0 ; ix < frm.length ; ix++) frmCollector.appendChild(frm[ix]); return frmCollector; }

但它每隔一秒提交一次。我该如何解决? 我的表单看起来像这样:

<form method="post">
<select class="..">
                                    <option value="">?</option>
                                    <option value=""></option>
                                    <option value=""></option>
                                    <option value=""></option>
                                </select>
</form>

1 个答案:

答案 0 :(得分:0)

由于你在问题中标记了jQuery,我认为以下内容应该有效。

$('<form />', {method:'POST'}).append($('form :input')).submit();

这会创建一个新的form元素,并将method属性设置为POST。然后,它会附加页面上每个其他form元素的输入。最后,它会提交您新创建的form元素。