innerHTML 顯示的數字3位一逗號

請問一下
因為我在JS有計算數字
然後innerHTML 到網頁上顯示
但我想把該數字顯示出來的時候可以3位一逗號....

h_obj = document.getElementById('h_'+obj_id).value ;
s_obj = document.getElementById(obj_id).value ;
if(h_obj!='')
{
now_sum -= h_obj ;
}
document.getElementById('h_'+obj_id).value = parseInt(s_obj,10) ;
now_sum += parseInt(s_obj,10) ;
document.getElementById('span1').innerHTML = \"<span class='index-fff-16px'>小計: </span><span class='purchase-call'>\" +now_sum+ \"</span><span class='index-fff-16px'></span>\" ;
tt = now_sum + now_sum2;
price = now_sum * 620;
price2 = now_sum2 * 640;
price3 = now_sum3 * 310;
price4 = now_sum4 * 320;
total = price + price2;
total3 = price + price2 + price3 + price4;

document.getElementById('span3').innerHTML = \"<span class='index-fff-16px'>總計: </span><span class='purchase-call'>\" +tt+ \"</span><span class='index-fff-16px'></span>\" ;
document.getElementById('price').innerHTML = \"<span class='index-fff-16px'>金額: </span><span class='purchase-call'>\" +price+ \"</span><span class='index-fff-16px'></span>\" ;
document.getElementById('total').innerHTML = \"<span class='index-fff-16px'>總金額: </span><span class='purchase-call'>\" +total+ \"</span><span class='index-fff-16px'></span>\" ;
document.getElementById('total3').innerHTML = \"<span class='index-fff-16px'>應付總金額: </span><span class='purchase-call'>\" +total3+ \"</span><span class='index-fff-16px'></span>\" ;
document.getElementById(\"priceaaa\").value = \"\"+total3+\"\";

評論

  • 建議你 另外寫一個 Js 的 function 來應對 你需要應對的狀況

    並在 寫程式的時候 決定加或不加

    function proNumStrFormat( num ){
    寫判斷 和 轉換
    return string;
    }

    document.getElementById('span3').innerHTML = \"總計: \" +proNumStrFormat(tt)+ \"\" ;

    希望能幫助到你
Sign In or Register to comment.