# 把这段code的秒钟、分钟和时钟的个位数变成两位数

maiko2010 2009-12-29 10:13:42

<script>
var secs = 300;
function countdown() {
if (secs <= 0)
{
window.open('www.yahoo.com.tw');
window.opener = null;
window.close();

}
else
{
var hh = Math.floor(secs/3600);
var mm = Math.floor("0" + (secs%3600) / 60);
var ss = ("0" + secs % 60).slice(-2);

document.getElementById("num").innerHTML =hh+":" + mm + ":" + ss;
secs--;

}
}
window.setInterval("countdown()",1000);
countdown();

</script>

...全文
151 3 打赏 收藏 举报

3 条回复

maiko2010 2010-03-23
• 打赏
• 举报

sundotLei 2009-12-29
• 打赏
• 举报

var time=hh+":" + mm + ":" + ss;
time=time.replace(/\b(\d)\b/g,"0\$1");
document.getElementById("num").innerHTML =time;

sundotLei 2009-12-29
• 打赏
• 举报

``````
<script>
var secs = 300;
function countdown() {
if (secs <= 0)
{
window.open('www.yahoo.com.tw');
window.opener = null;
window.close();

}
else
{
var hh = Math.floor(secs/3600);
var mm = Math.floor("0" + (secs%3600) / 60);
var ss = ("0" + secs % 60).slice(-2);
var time=hh+":" + mm + ":" + ss;
time=time.replace(/\b(\d)\b/g,"0\$1");
document.getElementById("num").innerHTML =time;
secs--;

}
}
window.setInterval("countdown()",1000);
countdown();

</script>
``````

8.7w+

Web 开发 JavaScript

2009-12-29 10:13