-1
新手問題:我如何將numberWithCommas傳遞給我的值,使我的號碼格式正確?代碼對我來說太複雜了。它正在工作,我只需要格式化數字。謝謝!數字格式通過.toString()
<script type="text/javascript">
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
if(!localStorage.Val1){
localStorage.Val1 = 1412015;
localStorage.Val2 = 20000;
localStorage.Val3 = 20000;
}
setInterval(function() {
var popcounter = document.getElementById('pop');
var ethanolcounter = document.getElementById('ethanol');
var meatlcounter = document.getElementById('meat');
localStorage.Val1 = parseInt(localStorage.Val1,10)+1;
localStorage.Val2 = parseInt(localStorage.Val2,10)+1000;
localStorage.Val3 = parseInt(localStorage.Val3,10)+1000;
popcounter.innerHTML = localStorage.Val1,10;
ethanolcounter.innerHTML = localStorage.Val2;
meatlcounter.innerHTML = localStorage.Val3;
},1000);
</script>
請說明。 –