<!--引入jquery.cookie.js 插件--> <script src="js/jquery.js" type="text/javascript" charset="utf-8"></script> <script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script> <!--逻辑功能代码 --> <script> $(function(){ /*仿刷新:检测是否存在cookie*/ if($.cookie("captcha")){ var count = $.cookie("captcha"); var btn = $(‘#getting‘); btn.html(count+‘秒后可重新获取‘).attr(‘disabled‘,true).css(‘cursor‘,‘not-allowed‘); var resend = setInterval(function(){ count--; if (count > 0){ btn.html(count+‘秒后可重新获取‘).attr(‘disabled‘,true).css(‘cursor‘,‘not-allowed‘); $.cookie("captcha", count, {path: ‘/‘, expires: (1/86400)*count}); }else { clearInterval(resend); btn.html("获取验证码").removeClass(‘disabled‘).removeAttr(‘disabled style‘); } }, 1000); } /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/ $(‘#getting‘).click(function(){ //手机验证码 var tel = $(‘#tel‘).val(); var btn = $(this); var count = 60; var resend = setInterval(function(){ count--; if (count > 0){ btn.html(count+"秒后可重新获取"); $.cookie("captcha", count, {path: ‘/‘, expires: (1/86400)*count}); }else { clearInterval(resend); btn.html("获取验证码").removeAttr(‘disabled style‘); } }, 1000); btn.attr(‘disabled‘,true).css(‘cursor‘,‘not-allowed‘); }); }); </script>