为什么jquery动态行不是由表单发布的

时间:2016-08-15 20:35:26

标签: php jquery forms laravel post

拥有此HTML:

{!! Form::open(array('route' => 'service.createNew', 'id' => 'newOrderForm')) !!}

    <tbody>
        <tr id="rowItem">
            <td>#</td>
            <td><input class="serviceItem form-control" name="serviceItem[]"></td>
            <td><select class="serviceType form-control" name="serviceType[]"><option>test</option></select></td>
            <td><input class="description form-control" name="description[]"></td>
            <td><input class="itemCount form-control" name="itemCount[]"></td>
            <td><input class="itemPrice form-control" name="itemPrice[]"></td>
            <td><input class="rowPrice form-control" name="rowPrice[]"></td>
            <td><button class="btn btn-danger btn-sm btn-rounded" disabled>x</button></td>
        </tr>

    </tbody>



</table>
<div class="row">
<div class="col-sm-12 invoice-block">
    <ul class="list-unstyled amounts text-small" align="right">
        <li class="text-extra-large text-dark margin-top-15">
            <strong>Celkem:</strong> $11,400
        </li>
    </ul>
    <br>
    <button class="btn btn-rounded btn-success btn-o pull-right" id="saveOrderButton">
    Vytvořit zakázku <i class="fa fa-check"></i></button>       
</div>
</div>
{!! Form::close() !!}

这个jQuery,它为最后一个TR添加了新行

$(document).on('click', '#addOrderItemButton', function(e) {

    newRow = '<tr id="rowItem"><td>#</td>';
    newRow += '<td><input class="serviceItem form-control" name="serviceItem[]"></td>';
    newRow += '<td><select class="serviceType form-control" name="serviceType[]"><option>test</option></select></td>';
    newRow += '<td><input class="description form-control" name="description[]"></td>';
    newRow += '<td><input class="itemCount form-control" name="itemCount[]"></td>';
    newRow += '<td><input class="itemPrice form-control" name="itemPrice[]"></td>';
    newRow += '<td><input class="rowPrice form-control" name="rowPrice[]"></td>';
    newRow += '<td><button class="btn btn-danger btn-sm btn-rounded delRowButton">x</button></td></tr>';

    $('#tableNewOrder').find('tr:last').after(newRow);

});

问题是,当我提交表单时,表单不会发送由jquery添加的行。我尝试使用.append()代替.after(),但它不起作用。

1 个答案:

答案 0 :(得分:0)

问题解决了 - 我只需要移动

Form::open()
<table>开始之前