倒计时插件

总喜欢整理一些小的demo,整合成插件,以后就方便用啦!

按钮的倒计时插件,参数直接给到秒数就好!

<script type="text/javascript">

$(".btn").click(function(){
	$(this).countdown(60);
});


$.fn.extend({
	 countdown:function(seconds){
	 	var time=seconds;
		var timer;
		var _this=$(this);
		_this.addClass("on");
		_this.find("a").html("重新获取("+seconds+"s)");
		timer=setInterval(function(){
			time--;
			if(time<0){
				clearInterval(timer);
				_this.removeClass("on");
				_this.find("a").html("获取验证码");
				time=seconds;
			}else{
				_this.find("a").html("重新获取("+time+"s)");
			}
		},1000);
		 }

});


</script>

  

原文地址:https://www.cnblogs.com/chaoli/p/5923539.html