Laravel - 如何在使用jquery附加表行后获取请求输入?

时间:2017-08-02 18:54:37

标签: javascript php jquery

如何使用jquery附加表后获取输入。我这里有默认的tbody。但是在我使用jquery附加它之后。我只能在这里获得默认tbody的第一个输入。

我的HTML

<input type="button" id="addProperty" class="btn btn-primary btn-sm" value="+">
<input type="button" id="removeProperty" class="btn btn-primary btn-sm" value="-">

{!! Form::open(['url' => 'admin/add_product',  'method' => 'post', 'enctype' => 'multipart/form-data']) !!}
Name:       <input type="text" name="pro_name" class="form-control"> <br/>
<table id="propertyTable">
<thead>
    <td> No </td>
    <td> Size</td>
    <td> Color</td>
    <td> Karat</td>
    <td> Price</td>
    <td> Stock</td>
</thead>`
<tbody class="test">
<tr>
    <td> 1 </td>
    <td>  <input name="property_size1" type="text" placeholder="Size" class="form-control"> </td>
    <td>  <input name="property_color1" type="text" placeholder="Color" class="form-control"> </td>
    <td>  <input name="property_karat1" type="text" placeholder="karat" class="form-control"> </td>
    <td>  <input name="property_price1" type="text" placeholder="Price" class="form-control"> </td>
    <td>  <input name="property_stock1" type="text" placeholder="Stock" class="form-control"> </td>
</tr>
</tbody>
{!! Form::close() !!}

我的JavaScript

 var totalProperty = 1;
    $('#addProperty').click(function(){
        totalProperty++;
        $('#propertyCount').val(totalProperty);
        $('#propertyTable > tbody:last-child').append('' +
            '<tr> ' +
            '<td> '+totalProperty +' </td> ' +
            '<td> <input name="property_size'+totalProperty+'" " type="text" placeholder="Size" class="form-control"> </td> ' +
            '<td> <input name="property_color'+totalProperty+'" type="text" placeholder="Color" class="form-control"> </td> ' +
            '<td> <input name="property_karat'+totalProperty+'" type="text" placeholder="karat" class="form-control"> </td> ' +
            '<td> <input name="property_price'+totalProperty+'" type="text" placeholder="Price" class="form-control"> </td> ' +
            '<td> <input name="property_stock'+totalProperty+'" type="text" placeholder="Stock" class="form-control"> </td> ' +
            '</tr>');
    });
    $('#removeProperty').click(function(){
       totalProperty--;
        $('#propertyCount').val(totalProperty);
        $('#propertyTable > tbody tr:last-child').remove();
        return false;
    });

Laravel

$totalProperty =  $request->input('total_property');
for($i = 1;$i<=$totalProperty;$i++){
    $property_size[$i] = $request->input('property_size'.$i);
    $property_color[$i] = $request->input('property_color'.$i);
    $property_karat[$i] = $request->input('property_karat'.$i);
    $property_price[$i] = $request->input('property_price'.$i);
    $property_stock[$i] = $request->input('property_stock'.$i); 
}
dd($property_size);

0 个答案:

没有答案