2014-04-25 3 views
-2

내가 뭘하려하는지 내 HTML이 도움이 될 때 5888처럼 보이게하는 것입니다. 그래서 html로 이것을 실행하면 "xxxx hours unitl xmas"의 카운트 다운이 필요합니다. 무엇이 질문인데, "xxxx"를 "x, xxx"로하고 싶습니다.자바 스크립트의 천 단위 구분 기호

<html> 
<body> 

<p>Clock!</p> 
<div id = "string"></div> 
<div id = "string2"></div> 

<script> 
var myVar=setInterval(function(){myTimer()},1000); 

function myTimer() 
{ 
var d=new Date(); 
var n=d.toLocaleDateString(); 
var t=d.toLocaleTimeString(); 
var m = d.toTimeString(); 
document.getElementById("string").innerHTML= n + m; 

var b = new Date(); 
b.setFullYear(2014,11,25); 
var dateHour1 = b.getTime(); 
var minutes=1000*60; 
var hours=minutes*60; 
var xHour = Math.round((dateHour1 - d)/hours); 
document.getElementById("string2").innerHTML = xHour +" Hours until xmas"; 
} 
</script> 
</body> 
</html> 

답변

0

당신은 같은 기능을 시도 할 수 있습니다 :이 html 형식이라면 나는 실제로 내 HTML을 편집 할 수 ++ 메모장을 사용하고

// Format a number n using: 
// p decimal places (two by default) 
// ts as the thousands separator (comma by default) and 
// dp as the decimal point (period by default). 
// 
// If p < 0 or p > 20 results are implementation dependent. 
function formatNumber(n, p, ts, dp) { 
    var t = []; 
    // Get arguments, set defaults 
    if (typeof p == 'undefined') p = 2; 
    if (typeof ts == 'undefined') ts = ','; 
    if (typeof dp == 'undefined') dp = '.'; 

    // Get number and decimal part of n 
    n = Number(n).toFixed(p).split('.'); 

    // Add thousands separator and decimal point (if requied): 
    for (var iLen = n[0].length, i = iLen? iLen % 3 || 3 : 0, j = 0; i <= iLen; i+=3) { 
    t.push(n[0].substring(j, i)); 
    j = i; 
    } 
    // Insert separators and return result 
    return t.join(ts) + (n[1]? dp + n[1] : ''); 
} 

formatNumber(5888, 0) // 5,888 
+0

를, 도움이 될 것입니다. – user3467039

관련 문제