以验证码倒计时为例:
var count = 60; function getCode(_this,uCode) { //判断倒计时元素是否存在 如果存在 不能再次发起 if($(_this).find("em").length>0){ alert("请稍后再试!"); return false; } //首次点击出发设置默认倒计时时间 count = 60; fajax("{{ path('admin_user_getcode') }}","u_code="+uCode,"get","json",function(data){ //获取验证码 if(data.code=="200"){ $(_this).prepend('60 '); var interval = setInterval(function(){ count--; $(_this).find("em").text(count); if(count == 0){ clearInterval(interval); $(_this).find("em").remove(); } },1000) }else{ alert(data.msg); } }); }
转载请注明:cooljun小窝 » js 定时触发器setInterval