js实现60秒倒计时

1.dom元素

<div class="box">
    <h2>剩余时间:<span class="clock">60</span>秒</h2>
</div>
<button>点击</button>

2.js 代码

var timeClock;
function sendCode() {
    var timer_num = 60;
    timeClock=setInterval(function(){
        timer_num--;
        $('.clock').html(timer_num);

        if (timer_num == 0) {
            clearInterval(timeClock);
            $('.clock').html(60);
        } 
    },1000)

}
$("button").click(function(){
    sendCode();
})

Last updated