如何减去总金额和支付金额并在另一个文本框中显示答案,我的代码不起作用。我需要自动显示余额,一旦支付总额…

编程

[ad_1]

XML
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  <script type="text/javascript">
      $(document).ready(function () {
                   $("#AmountId").change(function () {
              var a = parseInt($('#TotaltobePaid').val(), 10);
              var b = parseInt($('#AmountId').val(), 10);
              $('form').submit();
              var result=0;
              a = isNaN(a) ? 0 : a;
              b = isNan(b) ? 0 : b;
              if (a > 0 && b > 0)
                  result = a - b;
              $("#Balance").text(+result);

          });

      });

这是我的html代码

@Html.LabelFor(模型 => model.TotaltobePaid)

@Html.EditorFor(model => model.TotaltobePaid, new { name = “TotaltobePaid”, id = “TotaltobePaid” })

@Html.LabelFor(模型 => model.AmountPaid)

@Html.EditorFor(model => model.AmountPaid, new { name = “Amount”, id = “AmountId” })

@Html.LabelFor(模型 => model.Balance)

@Html.EditorFor(model => model.Balance, new { name = “Balance”, id = “Balance” })

解决方案1

JavaScript
<script type="text/javascript">
      $(document).ready(function () {
                   $("#AmountId").change(function () {
              var a = parseInt($('#TotaltobePaid').val(), 10);
              var b = parseInt($('#AmountId').val(), 10);
              $('form').submit();
              var result=0;
              a = isNaN(a) ? 0 : a;
              b = isNan(b) ? 0: b;
              if (a > 0 && b > 0)
                  result = a - b;
              $("#Balance").text(+result); 
          }); 
      });
</script>

b = isNan(b) ? 0:b;
检查线路

b = 为 NaN
(二)? 0:b;

解决方案2

函数减法()
var one=document.getElementById(“one”).value;
在哪里
wo=document.getElementById(“two”).value;
var Total = pardeFloat(一)_parseFloat(二);
document.getElementById(“总计).value=总计;

[ad_2]

コメント

标题和URL已复制