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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀