我在根据 jQuery 中的数量计算价格时遇到了一个小问题。这些是我的输入框。
Quantity: <input type="text" style="width: 50px;" name="quantity" id="quantity" class="txt" value="1" />
Price: <input type="text" style="width: 50px;" name="item_price" id="item_price" class="txt" value="2990" />
Total Price: <input type="text" style="width: 50px;" name="total_price" id="total_price" class="txt" value="" />
最佳答案
我假设您需要公式或如何获取输入元素的值:
var quantity = $("#quantity").val();
var iPrice = $("#item_price").val();
var total = quantity * iPrice;
$("#total_price").val(total); // sets the total price input to the quantity * price
alert(total);
为 Keyup 编辑:
$('#quantity').keyup(function() {
var quantity = $("#quantity").val();
var iPrice = $("#item_price").val();
var total = quantity * iPrice;
$("#total_price").val(total); // sets the total price input to the quantity * price
});
关于javascript - 从 jQuery 中的数量输入框计算价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12728092/