社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

输入字段上的jQuery onchage事件[已关闭]

Umair Mubeen • 5 年前 • 839 次点击  

我有一辆自行车,原价47000

我想把自行车卖了,现在自行车的售价是55000

我的问题是如何使用Jquery onchange函数计算剩余金额和利润金额

任何帮助都将不胜感激

$('.calculation').on('change', function() {
  cost = $("#bike_cost").text().trim()
  SaleAmt = $("#sale_amount").val()
  profit = SaleAmt - cost;
  receive_amount = $("#receive_amount").val();
  remaing = SaleAmt - receive_amount;
  $("#remaining_amount").val(remaing);
  $("#PROFIT_LOSS_AMOUNT").val(profit)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="form-group">
  <label class="">Bike Cost</label>
  <input type="text" id="bike_cost" required="" name="bike_cost" class="form-control calculation">
</div>

<div class="form-group">
  <label class="">Sell Amount</label>
  <input type="text" id="sale_amount" required="" name="sale_amount" class="form-control calculation">
</div>

<div class="form-group">
  <label class="">Receive Amount</label>
  <input type="text" id="receive_amount" required="" name="receive_amount" class="form-control calculation">
</div>

<div class="form-group">
  <label class="">Remaining Amount</label>
  <input type="text" id="remaining_amount" required="" name="remaining_amount" class="form-control calculation">
</div>

<div class="form-group">
  <label class="">Profit / Loss Amount</label>
  <input type="text" id="PROFIT_LOSS_AMOUNT" name="PROFIT_LOSS_AMOUNT" required="" class="form-control">
</div>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56030
 
839 次点击