我的代码 点击一次停止后再点开始然后在点击停止无法停止
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>倒计时<span style="color:red;font-size:50px;" id="time"></span></div>
<button id="star">点击开始</button>
<button id="stop">点击停止</button>
<script>
window.onload=function(){
op();
var st = setInterval(op,500);
var stop =document.getElementById('stop');
var star =document.getElementById('star');
stop.onclick=stp;
star.onclick=sta;
function sta(){
setInterval(op,500);
}
function stp(){
clearInterval(st);
}
}
function op(){
var time = document.getElementById('time');
var now = new Date();
var end = new Date('2018/05/20,5:20');
var s =parseInt((end.getTime() - now.getTime())/1000); //总共秒数
var ss =parseInt(s%60);
var m =parseInt(s/60%60);
var h =parseInt(s/(60*60)%24);
var d =parseInt(s/(24*60*60));
ss = check(ss);
m=check(m);
time.innerHTML=d+"天"+h+"小时"+m+'分'+ss+'秒';
if(s<=0){
time.innerHTML='时间结束啦,没有啦0.0!'
}
}
function check(i){
if(i<10){
i='0'+i;
}
return i;
}
</script>
</body>
</html>