2017-02-20 22 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); 
}); 
関連する問題