javascript 两个地方的数做加减乘除运算,保留两位小数,放到第三处
获取表单输入框的值进行运算:
<input type="text" id="txt1" value="123" />
<input type="text" id="txt2" value="123" />
var num1= $("#txt1").val();
var num2 = $("#txt2").val()
var total = num1+num2;
<center>
<div class="table-row-group">
<ul class="table-row">
<li style="border: 0px;font-size: 35px;">剩余</li>
<strong>
<li id="subtraction1" style="border: 0px;font-size: 35px;">0</li>
</strong>
<li style="border: 0px;font-size: 35px;">收入</li>
<strong>
<li id="subtraction2" style="border: 0px;font-size: 35px;">5478.28</li>
</strong>
<li style="border: 0px;font-size: 35px;">支出</li>
<strong>
<li id="subtraction3" style="border: 0px;font-size: 35px;">3304.70</li>
</strong>
</ul>
</div>
</center>
<script language="javascript">
function subtraction(first,second){ //两个数相减,相除,相乘 - / *,加法要这样 first*1 + second*1
var results = first - second;
results = results.toFixed(2);
return results;
}
$("#subtraction1").text(subtraction($("#subtraction2").text(),$("#subtraction3").text()));
</script>
信息科技 2020-04-10 08:21:55 通过 网页 浏览(3164) 打印
共有0条评论!