請(qǐng)求短信驗(yàn)證后,60秒內(nèi)不能再次點(diǎn)擊
例子:
HTML代碼
<button type='button' title='點(diǎn)擊發(fā)送短信'>點(diǎn)擊發(fā)送短信</button>
JS代碼
$('button').click(function(){
//點(diǎn)擊發(fā)送后,禁止點(diǎn)擊
$('button').attr('disabled',true);
//設(shè)定時(shí)間為60秒
nums=60;
//定時(shí)器設(shè)定變量名,便于清除
clock = setInterval(doLoop, 1000);
}
function doLoop(){
nums--;
if(nums > 0){
$('button').html(nums);
$('button').attr('title',nums+'秒后重新發(fā)送');
}else{
//時(shí)間為0時(shí),清除定時(shí)器,可以再次點(diǎn)擊發(fā)送短信
clearInterval(clock); //清除js定時(shí)器
$('button').attr('disabled',false);
$('button').attr('title','點(diǎn)擊重新發(fā)送');
$('button').html('點(diǎn)擊發(fā)送短信');
}
}