2015-10-15 65 views
0

我也想加入我的HTML代碼
表,但我想它作爲數字格式
比如我想讓它格式化成這樣:盧比。 100.000)
所以「Rp」。需要自動添加對細胞的起點,也將數字格式將如上.. 對不起,我英文不好,這是我的代碼,並感謝您的時間:表數字格式和文本添加HTML

 <!DOCTYPE html> 
<html> 
<body> 

<title>Preventive Maintenance Analyzer Tools</title> 

<div id="container" style="width:1350px;height:600px"> 
<div id="header" style="background-color:#094AB2;width:1350px;height:50px"> 
<h1 style="font-family:verdana;color : white;">Preventive Maintenance Analyzer Tools</font></h1></div></div> 

<div id="menu" style="background-color:#DAE0DA;height:560px;width:150px;float:left;"> 
<img src = "taxi.png" width = "130" height = "130" align = "center"><br><br><br><br><br> 
<font size="4"><a href = "http://localhost/home.php">HOME</a><br><br></font> 
<font size="4"><a href = "http://localhost/entry.html">CREATE NEW</a><br><br></font> 
<font size="4"><a href = "">SETTINGS</a></font><br><br><br><br><br></br> 
<img src = "taxi2.png" width = "140" height = "130" align = "center"> 
</div> 

<h2><center>Silahkan Isi Detail Form Dibawah Ini</center></h2> 

<div align = "center"> 
<fieldset> 
<legend><b>Detail Onsite</b></legend> 

Dari : 
<select name="dari"> 
<option value="co">Cyber Office</option>  
</select><br><br>` 

Tujuan PM : 
<select id="tujuan" name="tujuan"> 
<option value="abb">ABB Sakti Industri</option> 
<option value="ace">ACE Life Assurance</option> 
<option value="cigna">Asuransi Cigna</option> 
<option value="bahana">Bahana Securities</option> 
<option value="cimb">Bank CIMB</option> 
<option value="dki">Bank DKI</option> 
<option value="icbc">Bank ICBC Indonesia</option> 
<option value="bni">Bank BNI</option> 
<option value="courts">Courts Retail Indonesia</option> 
<option value="ffi">Frisian Flag Indonesia</option> 
<option value="gel">Great Eastern Life Indonesia</option> 
<option value="komatsu">Komatsu Indonesia</option> 
<option value="pertamina">Pertamina EP</option> 
<option value="rscm">Rumah Sakit Cipto Mangunkusomo (RSCM)</option> 
<option value="siloam">Siloam Hospital</option> 
<option value="takeda">Takeda Indonesia</option> 
<option value="vni">Visionet</option> 
</select><br><br> 

Cuaca : 
<select id="cuaca" name="cuaca"> 
<option value="normal">Normal/Cerah</option> 
<option value="gerimis">Gerimis</option> 
<option value="hujan">Hujan</option> 
</select><br><br> 

Faktor Eksternal (contoh demo, banjir, macet luar biasa dll) : <br> 
<select id="fe" name="fe"> 
<option value="false">Tidak Ada</option> 
<option value="true">Ada</option> 
</select><br><br> 

<a href="javascript:void(0)" id="submit">Submit</a> 

</form> 
</div> 


<div id="output" style="display:none"> 


     <center><h2>Estimasi Claim</h2></center> 
     <table border="4" ALIGN="center" > 
     <tr> 
     <th>Keterangan</th> 
     <th>Estimasi</th> 
     </tr> 
     <td> Estimasi Argo Taxi </td> 
     <td align="right" id="output_t1"></td> 
     <tr> 
     <td> Cuaca </td> 
     <td align="right" id="output_t2"></td> 
     <tr> 
     <td> Faktor Eksternal </td> 
     <td align="right" id="output_t3"></td> 
     <tr> 
     <td> Total Claim </td> 
     <td align="right" span class="price" id="output_t4"></td> 
     <tr> 
     </table> 

     <br><center><b>Selamat Atas Kemenangan Anda, Sampai Jumpa Pada Kemenangan Berikutnya</b></center> 

</div> 

<script> 
document.getElementById('submit').onclick = function(){ 

    document.getElementById('output').style.display = "block"; 

    var tujuan  = document.getElementById('tujuan').value; 
    var cuaca   = document.getElementById('cuaca').value; 
    var fe   = document.getElementById('fe').value; 

    var t1; 
    var t2; 
    var t3; 
    var t4; 

    switch(tujuan){ 

    case "abb": 
     t1 = 370000; 
     break; 

    case "ace": 
     t1 = 300000; 
     break; 

    case "cigna": 
     t1 = 170000; 
     break; 

    case "bahana": 
     t1 = 375000; 
     break; 

    case "cimb": 
     t1 = 300000; 
     break; 

    case "dki": 
     t1 = 300000; 
     break; 

    case "icbc": 
     t1 = 330000; 
     break; 

    case "bni": 
     t1 = 350000; 
     break; 

    case "courts": 
     t1 = 350000; 
     break; 

    case "ffi": 
     t1 = 430000; 
     break; 

    case "gel": 
     t1 = 360000; 
     break; 

    case "komatsu": 
     t1 = 580000; 
     break; 

    case "pertamina": 
     t1 = 370000; 
     break; 

    case "rscm": 
     t1 = 370000; 
     break; 

    case "siloam": 
     t1 = 50000; 
     break; 

    case "takeda": 
     t1 = 350000; 
     break; 

    case "visionet": 
     t1 = 20000; 
     break; 

    } 

    switch(cuaca){ 

    case "normal": 
     t2 = 0; 
     break; 

    case "gerimis": 
     t2 = 20000; 
     break; 

    case "hujan": 
     t2 = 40000; 
     break; 

    } 

    if(fe == 'true'){ 
    t3 = 40000; 
    } 
    else{ 
    t3 = 0; 
    } 
    t4 = t1 + t2 + t3; 
    console.log(t4); 

    document.getElementById('output_t1').innerHTML = t1; 
    document.getElementById('output_t2').innerHTML = t2; 
    document.getElementById('output_t3').innerHTML = t3; 
    document.getElementById('output_t4').innerHTML = t4; 
} 
</script> 

</body> 

<div id="footer" style="background-color:#094AB2;clear:both;text-align:center;"> 
<font color = "white">Copyright : M. Rinaldy Aulia 2015</font></div> 
</html> 
+0

哪裏是你的數據來自哪裏?你的意思是你的值必須放在output_tx單元中? – Terradon

+0

向我們展示您在JS中嘗試過的內容。 – Reinard

+0

謝謝大家,我添加了所有的源代碼.. –

回答

0

如果我理解正確的話,你想以確保您的號碼不讀取「370000」,而應改爲「Rp.37000」或「45000」應讀取「Rp.45000」

如果這是正確的,使用一個函數,將格式化數字。我在下面創建了一個名爲rp_beautifier的應用程序,並且還包含了一些關於如何實現它的示例代碼。希望我的理解正確,這有助於!


下面是函數(第3行,我們添加 「RP」,也是1 $後的空間。如果是美元這將是 「$ 1」,而不是 「$ 1」)

function rp_beautifier(someNumber){ 
    someNumber = parseFloat(someNumber).toFixed(0); 
    someNumber = "Rp. " + String(someNumber).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1 ") 
    return someNumber; 
} 

這裏是你如何把它

document.getElementById('output_t1').innerHTML = rp_beautifier(t1); 
document.getElementById('output_t2').innerHTML = rp_beautifier(t2); 
document.getElementById('output_t3').innerHTML = rp_beautifier(t3); 
document.getElementById('output_t4').innerHTML = rp_beautifier(t4);