2015-10-15 68 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);