Cara mengurangi jumlah total dan jumlah yang dibayarkan dan menampilkan jawabannya di kotak teks lain

pemrograman

[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);

          });

      });

inilah kode html saya

HTML
@Html.LabelFor(model => model.TotaltobePaid)
 

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

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

@Html.EditorFor(model => model.AmountPaid, new { name = "Amount", id = "AmountId" })
<button class="btn btn-primary" id="AmountButton">Go</button>
 

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

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

Apa yang saya coba:

<pre lang="HTML">@Html.LabelFor(model => model.TotaltobePaid)
 

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

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

@Html.EditorFor(model => model.AmountPaid, new { name = "Amount", id = "AmountId" })
<button class="btn btn-primary" id="AmountButton">Go</button>
 

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

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

Solusi 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;
periksa salurannya

b = adalahNaN
(B) ? 0:b;

Solusi 2

pengurangan fungsi()
var one=document.getElementById(“satu”).nilai;
Di mana
wo=document.getElementById(“dua”).nilai;
var total = pardeFloat(satu)_parseFloat(dua);
document.getElementById(“total).nilai=total;

[ad_2]

コメント

タイトルとURLをコピーしました