Javascript keyup 调用其他 table 值

Javascript keyup call other table value

我有一个 table 这样的:

<tbody id="invoice_item">  
<tr>   
<td><input name='qty[]' type='text' class='form-control form-control-sm qty' value='0'></td>
        <td><input name='price[]' type='text' class='form-control form-control-sm price' value='0'></td>
        <td><input name='sub_total[]' type='text' class='form-control form-control-sm sub_total' value='0' readonly></td>
</tr>
</tbody>

我想 Javascript 当 qty/price 更改小计也更改时。 我的 js:

 $("#invoice_item").delegate(".qty","keyup",function(){
    var qty = $(this).val();
    var price = tr.find(".price").val();
    alert(price);
    var sub_total = qty * price;
    alert(sub_total);
    tr.find(".sub_total").html(sub_total);


    })
    $("#invoice_item").delegate(".price","keyup",function(){
      var price = $(this).val();
      var qty = tr.find(".qty").val();
      alert(qty);

      })

看来问题是tr.find(".").val();。 我试着提醒它,但没有用..任何人都可以帮忙吗?我如何调用其他输入? $(this).val();没问题。

delegate() 在 v 3.0 中已弃用。您正在使用哪个 jquery?

您可以使用新的 on 方法将事件附加到输入标签本身,如下所示:

$(".qty").on("keyup",function(){}

要获取其他输入值,您可以使用:

$(".price").val()

我解决了, 我必须定义它 var tr = $(this).parent().parent();

谢谢大家!