【问题标题】:Number input and jquery [duplicate]数字输入和jquery [重复]
【发布时间】:2017-07-09 20:43:21
【问题描述】:

我有这张桌子:

<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 添加的新行中的 ubicated 数量输入它不起作用,如果我进行更改警报不会出现,我做错了什么?谢谢!

【问题讨论】:

  • 使用.on 函数。 $(".quantity").on('change', function () {});

标签: php jquery html-table rows


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-14
    • 2013-05-17
    • 2017-03-22
    • 1970-01-01
    • 2021-06-26
    • 2011-08-15
    • 1970-01-01
    • 2017-08-03
    相关资源
    最近更新 更多