如何在使用jQuery提交之前将自定义字段动态添加到表单中

如何在使用jQuery提交之前将自定义字段动态添加到表单中,jquery,forms,codeigniter,Jquery,Forms,Codeigniter,我复制了jQuery,但不知道如何管理它。我尝试了很多方法,也尝试了一些代码 var rowNum=0; 函数addRow(frm){ rowNum++; var row='我尝试了这个方法,它对我有效 <div class="input-group control-group after-add-more"> <label><input type="text" name="dayplans[title][

我复制了jQuery,但不知道如何管理它。我尝试了很多方法,也尝试了一些代码

var rowNum=0;
函数addRow(frm){
rowNum++;

var row='

我尝试了这个方法,它对我有效

            <div class="input-group control-group after-add-more">


                <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
                <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
                <div class="input-group-btn">
                    <button class="btn btn-success add-more" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
                </div>
            </div>

            <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
            <div class="copy-fields" style="display: none">
                <div class="control-group input-group" style="">
                    <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
                    <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
                    <div class="input-group-btn">
                        <button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
                    </div>
                </div>
            </div>

    <script type="text/javascript">

        $(document).ready(function() {

            //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
            $(".add-more").click(function(){
                var html = $(".copy-fields").html();
                $(".after-add-more").after(html);
            });
//here it will remove the current value of the remove button which has been pressed
            $("body").on("click",".remove",function(){
                $(this).parents(".control-group").remove();
            });

        });
</script>


添加
去除
$(文档).ready(函数(){
//在这里,首先使用name类copy字段获取div的内容,并将其添加到“after add more”div类之后。
$(“.add more”)。单击(函数(){
var html=$(“.copy fields”).html();
$(“.after添加更多”).after(html);
});
//在此,它将删除已按下的删除按钮的当前值
$(“body”)。在(“单击”,“删除”,函数()上){
$(this.parents(“.control group”).remove();
});
});

您想动态重复字段吗?是的,我想重复字段,就像有days平面部分,其中包括day和description。所以我想用jquery重复这两个字段
            <div class="input-group control-group after-add-more">


                <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
                <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
                <div class="input-group-btn">
                    <button class="btn btn-success add-more" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
                </div>
            </div>

            <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
            <div class="copy-fields" style="display: none">
                <div class="control-group input-group" style="">
                    <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
                    <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
                    <div class="input-group-btn">
                        <button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
                    </div>
                </div>
            </div>

    <script type="text/javascript">

        $(document).ready(function() {

            //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
            $(".add-more").click(function(){
                var html = $(".copy-fields").html();
                $(".after-add-more").after(html);
            });
//here it will remove the current value of the remove button which has been pressed
            $("body").on("click",".remove",function(){
                $(this).parents(".control-group").remove();
            });

        });
</script>