0
我寫了這個簡單的JS定時器,我有if
幾分鐘的問題,它仍然寫在第一秒00:01,第二秒000:02 ......如果你瞭解我。請你能幫助我嗎?謝謝將字符串格式化爲字符串
var sec = 0;
var min = 0;
var time;
function timer() {
sec++;
if (sec < 10) {
sec = "0" + sec;
}
if (min < 10) { //here is problem I think
min = "0" + min;
}
if (sec == 60) {
sec = 0;
min++;
}
if (sec == 5) { //this is just a function test
document.getElementById("myForm").submit();
}
document.getElementById("myTimer").innerHTML = min + ":" + sec;
}
function start() {
time = setInterval("timer()", 1000);
}
注意,優選的是,傳遞函數的參考而不是字符串作爲第一個參數爲*的setInterval *,所以'的setInterval(定時器,1000)'。 ;-) – RobG