javascript代码实例教程-Jquery插件实现点击获取验证码后60秒内禁止重新获取

发布时间:2019-01-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-Jquery插件实现点击获取验证码后60秒内禁止重新获取脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

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

效果图:

Jquery插件实现点击获取验证码后60秒内禁止重新获取

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

 

代码如下:


<!DOCTYPE htML>
<html>
<head>
<;meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<tITle>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js" ></script>
<script src="jquery.cookie.js" ></script>
<style type="text/css">
    * {margin: 0; padding: 0; font-family: "Microsoft Yahei";}
    .captcha-box {width: 360px; height: 34px; margin: 30px; padding: 30px; border: #956E6F 1px dashed; border-radius: 5px; background-color: #FAf2F2;}
    #mobile { float: left; width: 180px; height: 32px; border: #e5e5e5 1px solid; line-height: 32px; text-indent: 8px; outline: none;}
    #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;}
</style>
<script>
    $(function(){
        /*仿刷新:检测是否存在cookie*/
        if($.cookie("captcha")){
            VAR count = $.cookie("captcha");
            var BTn = $('#getting');
            btn.val(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-Allowed');
            var resend = setInterval(function(){
                count--;
                if (count > 0){
                    btn.val(count+'秒后可重新获取').attr('disabled',true).css('cursor','not-allowed');
                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                }else {
                    clearInterval(resend);
                    btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
                }
            }, 1000);
        }
        /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
        $('#getting').click(function(){
            var btn = $(this);
            var count = 60;
            var resend = setInterval(function(){
                count--;
                if (count > 0){
                    btn.val(count+"秒后可重新获取");
                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                }else {
                    clearInterval(resend);
                    btn.val("获取验证码").removeAttr('disabled style');
                }
            }, 1000);
            btn.attr('disabled',true).css('cursor','not-allowed');
        });
    });
</script>
</head>
<body>
    <p class="captcha-box">
        <input type="text" id="mobile" maxlength="11" placeholder="请输入手机号码">
        <input type="button" id="getting" value="获取验证码">
    </p>
</body>
</html>

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-Jquery插件实现点击获取验证码后60秒内禁止重新获取全部内容,希望文章能够帮你解决javascript代码实例教程-Jquery插件实现点击获取验证码后60秒内禁止重新获取所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。