在计算总和值时将输出作为NaN

时间:2017-09-04 07:53:26

标签: javascript jquery

我正在尝试生成某些数字的SUM,但是在计算总和值时输出为NaN

以下是示例代码

Demo

$("#rTpe2").keyup(function(e){
  $("#rFor2").val((this.value * $("#PerHourRate2").val()).toLocaleString('en-IN'));
  $("#rFor3").val.toLocaleString('en-IN')(Number($("#rFor1").val().toLocaleString('en-IN')) + Number($("#rFor2").val().toLocaleString('en-IN')))
});

enter image description here

1 个答案:

答案 0 :(得分:1)

val().toLocaleString()无效。

如下所示: -

实施例: -



$('tr').find('td:eq(2) input').keyup(function(){
 var final_td_value = $(this).val()*  $(this).closest('td').prev('td').find('input').val();
 var final_bar_value =final_td_value+Number($("#rFor2").val().replace(/,/g , ''));
 $(this).closest('td').next('td').find('input').val(final_td_value.toLocaleString('en-IN'));
  $("#rFor3").val((Number($("#rFor1").val().replace(/,/g , ''))+Number($("#rFor2").val().replace(/,/g , ''))).toLocaleString('en-IN'))

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="gap10"></div>
<div class="container">             
  <table class="table table-bordered data" >
    <thead>
    <tr>
    <th colspan="4"><h3  style="text-align: left;margin-top:0px; margin-bottom:0px;">Technology Design Services</h3></th>
    </tr>
      <tr class="one">
        <th  >Service Area</th>
        <th>Per Hour Rate</th>
        <th>Number Of Hours</th>
        <th>Total Rate</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Service1</td>
        <td><div class="form-group num">
<input  name="" type="number" placeholder="" class="form-control input-md"id="PerHourRate1"type="text" value="2325" readonly>
</div></td>
        <td><div class="form-group num">
<input  name="" type="number" placeholder="" class="form-control input-md"value="0" id="rTpe1">
</div></td>
<td><div class="form-group num">
<input  name="" type="text" placeholder="" class="form-control input-md"value="0" id="rFor1" readonly>
   <tr>
        <td>Service2</td>
        <td><div class="form-group num">
<input  name="" type="number" placeholder="" class="form-control input-md"id="PerHourRate2"type="text" value="2025" readonly>
</div></td>
        <td><div class="form-group num">
<input  name="" type="number" placeholder="" class="form-control input-md"value="0" id="rTpe2">
</div></td>
<td><div class="form-group num">
<input  name="" type="text" placeholder="" class="form-control input-md"value="0" id="rFor2" readonly>

</div></td>
<input  name="Total" type="text" placeholder="" class="form-control input-md"value="0" id="rFor3" readonly>
&#13;
&#13;
&#13;