gpt4 book ai didi

javascript - 计算总和值时获取 NaN 输出

转载 作者:行者123 更新时间:2023-12-03 03:32:23 25 4
gpt4 key购买 nike

我试图生成一些数字的总和,但是,在计算总和值时得到的输出为 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

最佳答案

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>

关于javascript - 计算总和值时获取 NaN 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46032580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com