我希望能够一直看到游戏中的经过时间。我想能够把它放在“时间”,它不需要格式化或任何东西。几秒钟就会很棒。
document.getElementById("round_score").innerHTML = "Score: "+round_score+" | High Score: "+high_score+" | Elapsed Time: "+time;
答案 0 :(得分:2)
只需在开头创建一个日期,如下所示:
var start = new Date();
然后当你想要找到从现在开始减去的经过时间
(new Date() - start ) / 1000
所以把它们放在一起
var start = new Date();
var elapsed = (new Date() - start ) / 1000;
document.getElementById("round_score").innerHTML = "Score: "+round_score+" | High Score: "+high_score+" | Elapsed Time: "+elapsed;