function timer(time) { var btn = $("#sendButton"); btn.attr("disabled", true); //按钮禁止点击 btn.val(time <= 0 ? "发送动态密码" : ("" + (time) + "秒后可发送")); var hander = setInterval(function() { if (time <= 0) { clearInterval(hander); //清除倒计时 btn.val("发送动态密码"); btn.attr("disabled", false); return false; }else { btn.val("" + (time--) + "秒后可发送"); } }, 1000); } //调用方法 timer(30);