通过jquery.cookie.js插件可以快速实现“点击获取验证码后60秒内禁止重新获取(防刷新)”的功能

先到官网(http://plugins.jquery.com/cookie/ )下载cookie插件,放到相应文件夹,代码如下:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>Examples</title>
  7. <meta name="description" content="">
  8. <meta name="keywords" content="">
  9. <script src="<a href="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js" target="_blank" <a="">http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js</a> " ></script>
  10. <script src="jquery.cookie.js" ></script>
  11. <style type="text/css">
  12. * {margin: 0; padding: 0; font-family: "Microsoft Yahei";}
  13. .captcha-box {width: 360px; height: 34px; margin: 30px; padding: 30px; border: #956E6F 1px dashed; border-radius: 5px; background-color: #FAF2F2;}
  14. #mobile { float: left; width: 180px; height: 32px; border: #e5e5e5 1px solid; line-height: 32px; text-indent: 8px; outline: none;}
  15. #getting {float: left; height: 34px; margin-left: -1px; padding: 0 18px; text-align: center;  line-height: 34px; border: #e5e5e5 1px solid; background: linear-gradient(0deg, #f4f2f2 0%,#fbf9f9 100%); cursor: pointer; outline: none;}
  16. </style>
  17. <script>
  18. $(function(){
  19. /*仿刷新:检测是否存在cookie*/
  20. if($.cookie("captcha")){
  21. var count = $.cookie("captcha");
  22. var btn = $('#getting');
  23. btn.val(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');
  24. var resend = setInterval(function(){
  25. count--;
  26. if (count > 0){
  27. btn.val(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');
  28. $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
  29. }else {
  30. clearInterval(resend);
  31. btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
  32. }
  33. }, 1000);
  34. }
  35. /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
  36. $('#getting').click(function(){
  37. var btn = $(this);
  38. var count = 60;
  39. var resend = setInterval(function(){
  40. count--;
  41. if (count > 0){
  42. btn.val(count+"秒后可重新获取");
  43. $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
  44. }else {
  45. clearInterval(resend);
  46. btn.val("获取验证码").removeAttr('disabled style');
  47. }
  48. }, 1000);
  49. btn.attr('disabled',true).css('cursor','not-allowed');
  50. });
  51. });
  52. </script>
  53. </head>
  54. <body>
  55. <div class="captcha-box">
  56. <input type="text" id="mobile" maxlength="11" placeholder="请输入手机号码">
  57. <input type="button" id="getting" value="获取验证码">
  58. </div>
  59. </body>
  60. </html>

以上就是本文的全部内容了,希望大家能够喜欢。

参考来源: 
Jquery插件实现点击获取验证码后60秒内禁止重新获取
http://www.lai18.com/content/349866.html

Jquery插件实现点击获取验证码后60秒内禁止重新获取的更多相关文章

  1. jQuery实现发送短信验证码后60秒倒计时

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  2. 获取验证码,60秒倒计时js

    <input type="button" id="btn" value="免费获取验证码" /><script type= ...

  3. js 点击获取验证码后的倒数60s

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script ...

  4. js 验证码 倒计时60秒

    js 验证码 倒计时60秒 <input type="button" id="btn" value="免费获取验证码" /> & ...

  5. javaScript 验证码 倒计时60秒

    <input type="button" id="btn" value="免费获取验证码" /> <script type ...

  6. vue实现验证码倒计时60秒的具体代码

    vue实现验证码倒计时60秒的具体代码 <span v-show="show" @click="getCode">获取验证码</span> ...

  7. JS获取验证码后倒计时不受刷新及关闭影响

    HTML部分 <input type="button" id="code_btn" value="获取验证码"> JS部分 // ...

  8. jQuery实现发送验证码倒计时60秒

    前端HMTL: <div class="form_box"> <div class="line mb40"> <div class ...

  9. iOS-登录发送验证码时60秒倒计时,直接用

    __block NSInteger timeout= ; //倒计时时间 KWeakSelf dispatch_queue_t queue = dispatch_get_global_queue(DI ...

随机推荐

  1. linux基础知识(四)

    •查看ip地址,ifconfig命令 •重启.启动.停止网络命令 •service network restart/start/stop   •VMnet0:用于虚拟桥接网络下的虚拟交换机 •VMne ...

  2. delphi action学习

    procedure TEditAction.UpdateTarget(Target: TObject); begin if (Self is TEditCut) then Enabled := (Ge ...

  3. ted be grateful

    -------------------------------------------------------------- David Steindl-Rast: Want to be happy? ...

  4. 真机在wifi下调试android程序

    大家好,最近在学习android程序由于手机接口问题,调试程序的时候老是接触不良而不能正常调试,因此感到相当苦恼,于是在网上查找无线调试android的方法.经过研究和尝试现已成功无线调试程序,方法分 ...

  5. 使用虚拟机win7系统遇到问题及解决

    安装VMware并在其中安装win7专业版系统,这里不再赘述.因为...我就是照着百度来的.哈哈 说说使用中遇到的问题. 本来安装成功后,可以很愉快的运行着.后来莫名奇妙的出现了两个问题:1.虚拟机运 ...

  6. delphi项目中的modelsupport文件夹

    delphi项目中的modelsupport文件夹 今天写着写着突然发现多了一个这个文件夹..苦思不得其解  看着又难受  删了又重建 终于找到了  存此备查;Tools--option--toget ...

  7. Servlet 利用Cookie实现一周内不重复登录

    import java.io.IOException;import java.io.PrintWriter; import javax.servlet.ServletException;import ...

  8. P1159岳麓山上打水

    P1159岳麓山上打水 https://vijos.org/p/1159 dfsID,第一次听说这东西,但是感觉不太靠谱啊. 一开始的时候,想到了排个序后,然后进行dp,如果要输出字典序最小其实还是可 ...

  9. Linux系统编程-setitimer函数

    功能:linux系统编程中,setitimer是一个经常被使用的函数,可用来实现延时和定时的功能. 头文件:sys/time.h 函数原型: int setitimer(int which, cons ...

  10. HttpClient请求发送的几种用法:

    /// <summary> /// HttpClient实现Post请求 /// </summary> static async void dooPost() { string ...