<html>
<body onload="countTime()">
<div id="text"></div>
<script type="text/javascript">
var start=Date.now();
var c=document.getElementById("text");
function showTime(){
var nowTime=60-Math.floor((Date.now()-start)/1000);
if(nowTime <0 ){break;}
c.innerHTML="left time is "+ nowTime +" seconds";
}
function countTime(){
c.innerHTML="left time is 60 seconds";
setInterval(showTime,1000);
}
</script>
</body>
</html>
上面的代码去掉if(nowTime <0 ){break;},可以运行,为何加上它,无法正常运行?
月关宝盒
相关分类