我需要帮助在MileagePointsObj.innerHTML
函数中向calcMileagePoints
添加逗号。现在它被设置为舍入到最接近的10。
<script type="text/javascript">
window.onload=function() {
LapTimeObj = document.getElementById('InputLaptime');
RaceLengthObj = document.getElementById('InputRaceLength');
MileagePointsObj = document.getElementById('TDMileagePoints');
document.getElementById('btnReset').onclick = resetInputs;
document.getElementById('btnCalc').onclick = calcMileagePoints;
}
function resetInputs() {
LapTimeObj.value = '';
RaceLengthObj.value = '';
MileagePointsObj.innerHTML = '';
}
function calcMileagePoints() {
var LapTime = new Number(LapTimeObj.value);
var RaceLength = new Number(RaceLengthObj.value);
MileagePointsObj.innerHTML = '';
MileagePointsObj.innerHTML = parseInt(((RaceLength*60*60)/LapTime)*10 / 10, 10) * 10;
}
</script>
提前致谢!
杰罗姆
答案 0 :(得分:2)
如评论中所述,使用toLocaleString()
简单示例
let number = 123456789;
let numberWithComma = number.toLocaleString();
console.log(numberWithComma);
&#13;
答案 1 :(得分:0)
谢谢你的帮助!
前程万里(MileagePointsObj.innerHTML)=(parseInt(((RaceLength * 60 * 60)/ LapTime)* 10 / 10,10)* 10).toLocaleString()