复制器ajax和表格重置器

时间:2016-01-20 09:25:11

标签: javascript php jquery ajax

大家好,我有一个用户可以添加经验的网站,在添加经验的同时,他们可以添加和删除更多的字段,但在添加/追加的数据中,有一个输入类型日期,它会一直发送相同的日期,如< / p>

我的代码是

<div class="full_exp_9092k" id='duplicater'>
    <div class="full_one_row_009so">
        <div class="obe_left_dibbhsy78">
            <div class="header_009sos00dd_d">
                Company Name <span>*</span>
            </div>
            <div class="maind_TAxefst67s77s">
                <input type="text" name="comp[]" required placeholder="company Name" class='cname_990s_EXp'/>
            </div>
        </div>
        <div class="obe_left_dibbhsy78">
            <div class="header_009sos00dd_d">
                Department Name <span>*</span>
            </div>
            <div class="maind_TAxefst67s77s">
                <input type="text" name="dept[]" required placeholder="Department Name" class='cname_990s_EXp'/>
            </div>
        </div>
    </div>

    <div class="full_one_row_009so">
        <div class="obe_left_dibbhsy78">
            <div class="header_009sos00dd_d">
                From Date <span>*</span>
            </div>
            <div class="maind_TAxefst67s77s">
                <input type="date" class='TEx_About_allihh' name="exsdate[]"/>
            </div>
        </div>
        <div class="obe_left_dibbhsy78">
            <div class="header_009sos00dd_d">
                To Date <span>*</span>
            </div>
            <div class="maind_TAxefst67s77s">
                <span id='some_end_dateid'><input type="date" class='TEx_About_allihh' name="exedate[]"/></span>
            </div>
        </div>
    </div>

    <div class="full_one_row_009so">
        <div class="obe_left_dibbhsy78">
            <div class="header_009sos00dd_d"></div>
            <input type="button" name="addmore" value="Add More" class='button small white' onclick='duplicate();'/>
        </div>
        <div class="small_cane_font_col">Currently working <input type="radio" name="workingnow[]" value="1" id="click_working_now"/></div>
    </div>
</div>

JS

<script>
    $(function() {
        $("input[type='date']").cdp({
            addNullOption : true,
            nullOptionText: "Select"
        });
    });

    var i = 0;
    var original = document.getElementById('duplicater');

    function duplicate(){
        $('#some_end_dateid').show();
        var clone = original.cloneNode(true); // "deep" clone
        i = ++i;
        clone.id = "duplicetor"+ i; // there can only be one element with  an ID
        original.parentNode.appendChild(clone);
        addButton(clone.id,i);
        clearCloneForm(clone.id);
    }

    function clearCloneForm(id){ 
        var divId = '#'+id;
        $(divId).find(".cname_990s_EXp").each(function() {
            $(this).val('');
        });
    }

    function addButton(id,ii){ 
        var divId = '#'+id;
        $(divId).append('<input type="button" value="Remove" class="button small red" style="margin-left:5px;" id="'+ii+'" onclick="rBlock('+ii+')" />');
    }
</script>

问题

当我提交日期并打印

PHP

     $comps=$_POST['comp'];
     $exedate=$_POST['exedate'];
     $exsdate=$_POST['exsdate'];
     $dept=$_POST['dept'];
     @$workingnow=$_POST['workingnow'];

      print_r($exedate);

我在所有数组中获得的日期与第一行中的日期相同。

1 个答案:

答案 0 :(得分:0)

我无法复制问题 - 发布时所有日期都不同(如果每次手动输入)。但是,如果我输入一个from和迄今为止然后克隆它们,那么也会克隆这些值,然后在发布表单时,值将是相同的。我认为cuplrit是你尝试从克隆节点中清除值的方式,它错过了日期字段。将功能更改为:

function clearCloneForm(id){ 
    var divId = '#'+id;
    $(divId).find(".cname_990s_EXp,.TEx_About_allihh").each(function() {
        $(this).val('');
    });
}