$(function () { var wait=60; function time( o ){ if (wait == 0) { o.toggleClass(‘bg-lv‘); o.removeAttr("disabled"); o.val("获取验证码"); wait = 60; } else { o.removeClass(‘bg-lv‘); o.attr("disabled",true); o.val("重新发送(" + wait + ")"); wait--; setTimeout(function() { time(o); }, 1000) } } $("#getCode").click(function(){ var formData = $(‘#form‘).serialize(); $.ajax({ url:"{:url(‘login/index‘)}", data:formData, dataType:"json", type:"post", success:function(r){ if(r.check==1){ time($("#getCode")); alert(r.msg); }else{ alert(r.msg); } } }) return false; }); });