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>
	<div class="captcha-box">
		<input type="text" id="mobile" maxlength="11" placeholder="请输入手机号码">
		<input type="button" id="getting" value="获取验证码">
	</div>
</body>
</html>
时间: 2024-07-29 04:27:05

Jquery插件实现“点击获取验证码后60秒内禁止重新获取(仿刷新)”的相关文章

Jquery插件 防刷新倒计时 “点击获取验证码后60秒内禁止重新获取

Jquery插件实现"点击获取验证码后60秒内禁止重新获取(防刷新)" 效果图: 先到官网(http://plugins.jQuery.com/cookie/)下载cookie插件,放到相应文件夹,代码如下: 1 <style type="text/css"> 2 * {margin: 0; 3 padding: 0; 4 font-family: "Microsoft Yahei"; 5 } 6 .captcha-box { 7 w

点击获取验证码后60秒内禁止重新获取(防刷新)

<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(f

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

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> var countdown=60; functi

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

<input type="button" id="btn" value="免费获取验证码" /><script type="text/javascript">var wait=60;function time(o) {        if (wait == 0) {            o.removeAttribute("disabled");                  

对安卓获取验证码倒计时60秒Button按钮的简单封装

鉴于经常在注册获取验证码时候需要一个倒计时按钮觉得很麻烦,抽点时间写了一个TimeButton 键鼠下特性, TimeButton使用的时候跟普通Button一样没有冲突, TimeButton在倒计时的时候返回了如果没有超过剩下的时间再次进入会继续跑时哦, TimeButton里面完成了按钮的点击显示和倒计时逻辑, TimeButton在activity销毁后也会销毁不会像线程一样还在后台跑, TimeButton的显示文字和倒计时都可以自行设置当然也有默认的, 原创地址 http://wri

发送短信后60秒内阻止点击 + 手机号码检测

messageBox 是一个通知的Toast, function SMSCaptcha() { this.smsbtn = $('.sms-captcha-btn'); this.flag = true; this.mobileNumber = $('.mobile-number');} SMSCaptcha.prototype.mobileNumberChecking = function () { var self = this; mobleNumber = self.mobileNumbe

Android获取验证码后倒计时程序

在开发是经常会遇到获取短信验证码,然后获取验证码后需要等待1分钟倒计时,这是是不能再次发送短信请求的,这是需要一个倒计时程序 这里我封装了一个Util类,希望对开发的小伙伴能有帮助, public class TimeCountUtil extends CountDownTimer { private Activity mActivity; private Button btn;//按钮 // 在这个构造方法里需要传入三个参数,一个是Activity,一个是总的时间millisInFuture,

前端常用库-发送短信验证码倒计时60秒

带ajax验证原文链接:http://www.cnblogs.com/steed-zgf/archive/2012/02/03/2336984.html <!doctype html> <head> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript">

js 验证码 倒计时60秒

<input type="button" id="btn" value="免费获取验证码" /> <script type="text/javascript"> var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value="免费获取验证码"; wai