倒計時插件

總喜歡整理一些小的demo,整合成插件,之後就方便用啦!javascript

按鈕的倒計時插件,參數直接給到秒數就好!html

<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>
相關文章
相關標籤/搜索