gpt4 book ai didi

Javascript keyup 调用其他表值

转载 作者:行者123 更新时间:2023-12-03 03:01:58 26 4
gpt4 key购买 nike

我有一个这样的表:

<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。我的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()

关于Javascript keyup 调用其他表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47341172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com