您现在的位置是:首页> 网站开发> jQuery
jquery防刷新发送验证码倒计时
- 5094人已阅读
- 时间:2018-10-16 09:00:48
- 分类:jQuery
<!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>
<div class="captcha-box">
<input type="text" id="mobile" maxlength="11" placeholder="请输入手机号码">
<input type="button" id="getting" value="获取验证码">
</div>
</body>
</html>
下一篇:PHP对字符串指定替换次数
相关文章
- 解决百度编辑器UEditor行号错位问题
- ThinkPHP5开发项目时,利用jQuery的Ajax异步上传图片并实时预缆
- jQuery QQ表情插件包使用方法jquery.qqFace.js
- jQuery的区别:$().click()和$(document).on('click','要选择的元素',functi
- Jquery根据name属性查找
- Jquery添加删除disabled属性的方法
- jQuery根据表单name获取值的方法
- 基于jquery的表格隔行变色
- jquery鼠标移上与移出事件
- TP5验证码实现教程
- TP5验证器使用实例
- Thinkphp5整合阿里大鱼的方法超级教程看了就能用.
- php验证身份证号是否正确函数