一个简单的JavaScript倒数计时器的代码?我想使用一个简单的倒数计时器,从函数运行到0开始的30秒开始。没有毫秒。怎么编码?
3 回答
当年话下
TA贡献1890条经验 获得超9个赞
var count=30;var counter=setInterval(timer, 1000); //1000 will run it every 1 secondfunction timer(){ count=count-1; if (count <= 0) { clearInterval(counter); //counter ended, do something here return; } //Do code for showing the number of seconds here}
<span id="timer"></span>
timer()
function timer(){ count=count-1; if (count <= 0) { clearInterval(counter); return; } document.getElementById("timer").innerHTML=count + " secs"; // watch for spelling}
添加回答
举报
0/150
提交
取消