var btn = document.getElementById('btn')
console.log(btn);
var num = 6
btn.onclick = function () {
var that = this
var timer = setInterval(function () {
num--
that.innerHTML = num
if (num <= 0) {
that.disabled = false
that.innerHTML = '重新发送'
num = 6
clearInterval(timer) //清除计时器
}
}, 1000)
this.disabled = true
}
// 2 es6 箭头函数
// btn.onclick = function () {
// var timer = setInterval(() => {
// num--
// this.innerHTML = num
// if (num <= 0) {
// this.disabled = false
// this.innerHTML = '重新发送'
// num = 6
// clearInterval(timer)
// }
// }, 1000)
this.disabled = true
}
js计时器手机验证码
最新推荐文章于 2024-07-22 08:55:10 发布