使用jQuery附加的输入字段不会在POST php上提交

时间:2014-03-21 21:04:11

标签: php jquery html

我这样做了:

https://stackoverflow.com/a/21724399/267304

但是当表单提交数组时,只包含第一个输入数组值。

这是我的HTML:

<form method="post" accept-charset="utf-8">
<table id="deliveryZipTable" class="table">
    <thead>
        <tr>
            <th width="150">Post nr</th>
            <th width="150">Pris</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr class="newZipDeliveryBox hide">
            <td><input type="text" name="newd_zipcode[]" value="" placeholder="Fx: 999-2000 eller 2200"></td>
            <td><input type="text" name="newd_price[]" value="" placeholder="Pris"></td>
            <td></td>
        </tr>
    </tbody>
</table>

<a class="pointer newZipDelivery">+Add new</a>

和jQuery:

    $('.newZipDelivery').click(function(){
        if($('.newZipDeliveryBox').hasClass('hide'))
        {
            $('.newZipDeliveryBox').removeClass('hide');
        }else{
            var $clone = $('.newZipDeliveryBox').clone();
            $clone.removeClass('newZipDeliveryBox');

            $('#deliveryZipTable > tbody > tr:last').after($clone);
        }
    });

该脚本的作用是第一次显示(删除类&#39;隐藏&#39;),如果再次按add new,它会克隆并追加。

似乎克隆的tr内部的输入被附加,不会出现在表单提交上。任何解决方案?

如果我的html中有多个:

<input type="text" name="newd_zipcode[]" value="" placeholder="Fx: 999-2000 eller 2200">
<input type="text" name="newd_zipcode[]" value="" placeholder="Fx: 999-2000 eller 2200">
<input type="text" name="newd_zipcode[]" value="" placeholder="Fx: 999-2000 eller 2200">

所有这些提交都很好。

所以它只在克隆和附加输入字段时,数据在提交时不会发送POST。有什么帮助吗?

0 个答案:

没有答案