应用场景:点击按钮,获取验证码,倒计时60秒
【html】
<a id="sendVertifyCode" style="width:100px;float: right;color:red;height: 30px;line-height: 30px;">获取验证码</a> <label id="codeMsg" style="width:100px;float: right;color:red;height: 30px;line-height: 30px;display: none;">还剩60秒</label>
var t=59; var inter = setInterval(function(){ $("#codeMsg").html("还剩"+t+"秒"); if(t <= 0) { clearInterval(inter); //隐藏标签 $("#sendVertifyCode").css("display","block"); //倒计时 $("#codeMsg").css("display","none"); } t--; }, 1000);