タイマーを作成しましたが、5 秒または 10 秒ごとに何かを行う必要があります。setTimeout または setInterval 関数を使用したくありませんが、このタイマーを使用する場合、秒の値に対処する方法がわかりません。5000 などと書くべきでしょうか?
function display(){
var endTime = new Date();
var timeDiff = endTime - startTime;
timeDiff /= 1000;
var seconds = Math.round(timeDiff % 60);
timeDiff = Math.floor(timeDiff / 60);
//showing the seconds passed
$("#time").text(seconds);
setTimeout(display,1000);
}
//starts the timer
$("#start").click(function() {
startTime = new Date();
setTimeout(display,1000);
});
/confirms it is 5 seconds
if (timeDiff == 5){
alert('now');
}