2017-02-20 52 views
0

我有这个表:数字输入和jQuery

<table id="product" class="table table-bordered table-striped"> 
    <thead> 
    <tr> 
     <th>Id</th> 
     <th>Cantidad</th> 
     <th>Producto</th> 
     <th>Marca</th> 
     <th>Precio</th> 
     <th>Importe</th> 
     <th>Serial</th> 
    </tr> 
    </thead> 
    <tbody> 
    </tbody> 
</table> 

我行添加到该表与此jQuery代码:

$("#name").autocomplete({ 
    source: 'http://sosacelulares.com/index.php/product/search', 
    minLength: 1, 
    select: function (event, ui) { 
     var value = ui.item.value; 
     var data1 = value.split("-"); 
     var data = data1[0].split(" "); 
     $("#product").show(); 

     var v = data[1]; 

     $.ajax({ 
      async:true, 
      type: "POST", 
      dataType: "html", 
      contentType: "application/x-www-form-urlencoded", 
      url:"http://sosacelulares.com/index.php/product/get", 
      data:"id="+v, 
      success: function(response) { 
      var returnedData = JSON.parse(response); 

      $("#product > tbody").append('<tr><td>' + returnedData[0].id_product + '</td><td><input min="1" type="number" style="width: 100px;" value="" class="form-control quantity" id="quantity" placeholder="Cantidad" required></td><td>' + returnedData[0].name + '</td><td>' + returnedData[0].brand + '</td><td><input type="text" style="width: 100px;" value="' + returnedData[0].buy_price + '" class="form-control" placeholder="Precio" required></td><td></td><td><a href=""><button type="submit" class="btn btn-success">Agregar Serial</button></a></td></tr>'); 
      } 
     }); 
    }, 

}); 

我只是寻找一个名字在文本输入,然后当我发现它只是将它添加到表格中。 的问题是,我加入他们有一些输入字段,它是添加量行我测试它像这样:

$(".quantity").change(function() { 
    alert(1); 
}); 

我不知道为什么,如果我改变量输入那它是在新行内,我用jquery添加它是行不通的,如果我改变警报不出现,我做什么坏?谢谢!

+0

使用'.on'功能。 '(“。quantity”)。on('change',function(){});' –

回答

0

试试这个:

$(document).on("change", ".quantity", function() { 
    alert(1); 
});