我正在构建一个发票系统,其中从数据库中检索项目名称和价格。价格取决于项目名称。
现在我必须这样做。
Price: <Input type="text" id="price" name="price" />
Qty : <Input type="text" id="qty" name="qty" />
Tax : <Input type="text" id="tax" name="tax" />
Discount : <Input type="text" id="disc" name="disc" />
Total : <Input type="text" id="total" name="total" value=" echo $total;"/>
我想自动填充总输入字段而无需使用以下公式重新加载
<?Php
$total = $price * $qty + $tax - $disc;
?>
最佳答案
需要在您的 html 和一些 jquery 脚本中分配类,
//Assign Amount class in your 4 html fields
Price: <Input type="text" id="price" name="price" class="amount" />
Qty : <Input type="text" id="qty" name="qty" class="amount"/>
Tax : <Input type="text" id="tax" name="tax" class="amount"/>
Discount : <Input type="text" id="disc" name="disc" class="amount"/>
Total : <Input type="text" id="total" name="total" value=" echo $total;"/>
$( document ).ready(function() {
$('input.amount').keyup(function(){
var price = $("#price").val();
var qty = $("#qty").val();
var tax = $("#tax").val();
var disc = $("#disc").val();
var total = $("#total").val();
total = ((parseFloat(price) * parseFloat(qty) + parseFloat(tax) - parseFloat(disc);
$("#total").val(parseFloat(total));
});
});
关于php - 如何实现依赖输入字段的Jquery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45707587/