html自动固定时间间隔按按钮,在Jquery HTML中的特定时间框架后启用按钮?

匿名用户

您只需将代码包装在一个函数中,并在事件单击时和代码运行开始时调用该函数,在函数内部添加了时间检查以清除间隔并重置计时器,并使用.setAttribute()和RemoveAttribute()禁用/启用按钮:

nullfunction enableButton() {

var timer2 = "00:30";

var interval = setInterval(function() {

var timer = timer2.split(':');

//by parsing integer, I avoid all extra string processing

var minutes = parseInt(timer[0], 10);

var seconds = parseInt(timer[1], 10);

--seconds;

minutes = (seconds < 0) ? --minutes : minutes;

if (minutes < 0) clearInterval(interval);

seconds = (seconds < 0) ? 59 : seconds;

//minutes = (minutes < 10) ? minutes : minutes;

$('.countdown').html(minutes + ':' + seconds);

timer2 = minutes + ':' + seconds;

if( minutes === 0 && seconds === 0) {

clearInterval(interval);

document.getElementById('demo').removeAttribute('disabled');

}

else {

document.getElementById('demo').setAttribute('disabled', true);

}

}, 100);

}

document.getElementById('demo').addEventListener('click', function() {

enableButton();

});

enableButton();

click

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值