计算一个< td> x另一个< td>在jQuery中 [英] Calculate one <td> x another <td> in jQuery
本文介绍了计算一个< td> x另一个< td>在jQuery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到NaN.我该如何做,并在每次更改数量时更新它?
I'm getting NaN. How can I do this and have it update every time time qty is changed?
$('input[name="qtybox"]').change(function(){
var price = parseInt($(this).text(), 10)
* parseFloat($(this).closest('#price').text(), 10);
$("#tPrice").html(price);
});
<td id="price">2.79</td>
<td id="qty-box"><input type="text" name="qtybox"></td>
<td id="tPrice"></td>
推荐答案
Are you looking for something like this jsFiddle example?
jQuery:
$('input.qtybox').each(function() {
$(this).keyup(function() {
var price = $(this).parent().siblings('td#price').text();
var qty = $(this).val();
$(this).parent().siblings('td#tPrice').html(isNaN( ((price * qty).toFixed(2)) ) ? 0 : ((price * qty).toFixed(2)));
})
})
这篇关于计算一个< td> x另一个< td>在jQuery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文