Home > Web Front-end > JS Tutorial > body text

Jquery plug-in implements prohibiting re-obtaining within 60 seconds after clicking to obtain the verification code_jquery

WBOY
Release: 2016-05-16 16:09:43
Original
1509 people have browsed it

The jquery.cookie.js plug-in can quickly implement the function of "prohibiting re-acquisition within 60 seconds after clicking to obtain the verification code (anti-refresh)"

Rendering:

First go to the official website (http://plugins.jquery.com/cookie/) to download the cookie plug-in and put it in the corresponding folder. The code is as follows:

Copy code The code is as follows:






Examples





<script><br>     $(function(){<br>         /*仿刷新:检测是否存在cookie*/<br>         if($.cookie("captcha")){<br>             var count = $.cookie("captcha");<br>             var btn = $('#getting');<br>             btn.val(count '秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');<br>             var resend = setInterval(function(){<br>                 count--;<br>                 if (count > 0){<br>                     btn.val(count '秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');<br>                     $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});<br>                 }else {<br>                     clearInterval(resend);<br>                     btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');<br>                 }<br>             }, 1000);<br>         }<br>         /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/<br>         $('#getting').click(function(){<br>             var btn = $(this);<br>             var count = 60;<br>             var resend = setInterval(function(){<br>                 count--;<br>                 if (count > 0){<br>                     btn.val(count "秒后可重新获取");<br>                     $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});<br>                 }else {<br>                     clearInterval(resend);<br>                     btn.val("获取验证码").removeAttr('disabled style');<br>                }<br>              }, 1000);<br>                btn.attr('disabled',true).css('cursor','not-allowed');<br>         });<br> });<br> </script>



          
          




The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!