我正在創建我的第一個Chrome瀏覽器擴展,它在瀏覽器啓動時啓動計時器。 例如:00:00:00 - > 00:00:01 - > 00:00:02 我粘貼了下面的代碼。這是做這件事的最佳選擇嗎?我想在瀏覽器打開時計算時間
$(function() {
startCount();
});
function startCount() {
timer = setInterval(count, 1000);
}
function count() {
var time_shown = $("#realtime").text();
var time_chunks = time_shown.split(":");
var hour, mins, secs;
hour = Number(time_chunks[0]);
mins = Number(time_chunks[1]);
secs = Number(time_chunks[2]);
secs++;
if (secs == 60) {
secs = 0;
mins = mins + 1;
}
if (mins == 60) {
mins = 0;
hour = hour + 1;
}
if (hour == 13) {
hour = 0;
}
$("#realtime").text(timezero(hour) + ":" + timezero(mins) + ":" + timezero(secs));
}
function timezero(digit) {
var str = digit + '';
if (digit < 10) {
str = "0" + str;
}
return str;
}
什麼是錯誤? –