dongqiao8421 2019-01-11 07:43
浏览 324
已采纳

如何计算javascript / jquery中的单价和数量变化?

I am having a small issue calculating price from Quantity in jQuery. Those are the input boxes I have.

<html>
   Quantity: <input type="text" style="width: 50px;" name="quantity" id="quantity" class="txt" value="1" />
   Unit Price: <input type="text" style="width: 50px;" name="item_price" id="item_price" class="txt" value="" />
   Amount: <input type="text" style="width: 50px;" name="total_price" id="total_price" class="txt" value="" />
</html>

Here I will show my jQuery code.Quantity ; price and Amount value also changes.jQuery Code, but unable to find the problem?

<script>
$('#quantity').click(function () {
        var number = $(this).val();
           var o_val = $("#unit_pricea").val();
           var op_val = number * o_val;
          $("#amounta").val(op_val);
          console.log(op_val);
        });
</script>

Here I will share my screen shots.

  1. First image whenever I enter unit price amount filed not fill:

First image whenever i enter unit price amount filed not fill

  1. Second image unit price can I change previous value of amount not change:

Second image unit price can i change previous value of amount not change

  1. Quantity will be change amount not changed:

Quantity will be change amount not changed

  • 写回答

2条回答 默认 最新

  • duangua5308 2019-02-15 07:12
    关注
    $('#unit_pricea').change(function () {
                 var number = $(this).val();
                    var o_val = $("#quantity").val();
                    var op_val = number * o_val;
                   $("#amounta").val(op_val);
    

    Change look like this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏