Boostrap dynically row with value

时间:2016-09-28 00:45:31

标签: javascript php twitter-bootstrap

我尝试在表中添加一个新行,但是这个新行中的所有字段每次都必须有一个新值 此脚本允许添加新行,但它不会自动更改行的值

                <table width="100%" cellpadding="5" cellspacing="0" border="0">
                  <tr>
                    <td><table class="table table-sm table-hover" id="mtable">
                      <thead>
                        <tr>
                          <th>id</th>
                          <th class="col-md-2">Fournisseur</th>
                          <th class="col-md-2">Groupe Clients</th>
                          <th class="col-md-2">Range Quantité</th>
                          <th class="col-md-2">Prix Fournisseur</th>
                          <th class="col-md-2">% Remise Client</th>
                          <th></th>
                        </tr>
                      </thead>
                      <tbody>
                           <tr>
                            <td>84 <input type="hidden" name="id" value="84" /></td>
                            <td class="col-md-2"><select name="suppliers_id[84]" id="suppliers_id[84]" class="form-control"><option value="">--Aucun--</option><option value="1" selected="selected">test</option></select></td>
                            <td class="col-md-2"><select name="customers_group_id[84]" id="customers_group_id[84]" class="form-control"><option value="" selected="selected">Normal</option><option value="1">Tarifs 1</option></select></td>
                            <td class="col-md-2"><input type="text" name="discount_quantity[84]" value="5" placeholder="Qty" class="form-control" /></td>
                            <td class="col-md-2"><input type="text" name="discount_supplier_price[84]" value="5" placeholder="Supplier Price" class="form-control" /></td>
                            <td class="col-md-2"><input type="text" name="discount_customer[84]" value="5" placeholder="Discount without %" class="form-control" /></td>
                            <td></td>
                          </tr>
.........


                           <tr>
                            <td>102 <input type="hidden" name="id" value="102" /></td>
                            <td class="col-md-2"><select name="suppliers_id[102]" id="suppliers_id[102]" class="form-control"><option value="">--Aucun--</option><option value="1" selected="selected">test</option></select></td>
                            <td class="col-md-2"><select name="customers_group_id[102]" id="customers_group_id[102]" class="form-control"><option value="" selected="selected">Normal</option><option value="1">Tarifs 1</option></select></td>
                            <td class="col-md-2"><input type="text" name="discount_quantity[102]" value="5" placeholder="Qty" class="form-control" /></td>
                            <td class="col-md-2"><input type="text" name="discount_supplier_price[102]" value="5" placeholder="Supplier Price" class="form-control" /></td>
                            <td class="col-md-2"><input type="text" name="discount_customer[102]" value="5" placeholder="Discount without %" class="form-control" /></td>
                            <td></td>
                          </tr>
                      </tbody>
                    </table></td>
                  </tr>
                </table>

下面,例如,我添加一个新值,但此值仅适用于第一列。 $ new_id(新id值)必须应用于所有列,每次添加列时,id都有新闻值。

我在javascript方面不擅长。一点帮助。 Tk的

<?php
  $new_id =  $id + 1;
?>



               <input id="row" value="<?php echo $new_id; ?>" placeholder="Enter Item Name"/><button type="button" id="irow">Insert Row</><br/><br/>

    <script>
      $('#irow').click(function(){
        if($('#row').val()){
          $('#mtable tbody').append($("#mtable tbody tr:last").clone());
          $('#mtable tbody tr:last :checkbox').attr('checked',false);
          $('#mtable tbody tr:last td:first').html($('#row').val());
        }else{alert('Enter Text');}
      });
    </script>

0 个答案:

没有答案