<head>
	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>

<input id="smspwd" type="button" value="短信获取" onclick='getSMS()'>

<script type="text/javascript">		
	function getSMS(){
		console.log(1)
		$("#smspwd").smsCountdown({begin: 10})
	}
</script>


<script type="text/javascript">		
	$.fn.extend({
		smsCountdown:function(){
			var params = {
				begin: arguments[0].begin || 0,
				way: arguments[0].way || 'input'
			};
			var $me = this;
			if(params.begin>0){
				$me.attr('disabled',true);
				var count = params.begin;		
				if(params.way == 'button'){
					var resend = setInterval(function(){
						count--;
						if (count > 0){
							$me.html("\u7b49\u5f85"+count+"\u79d2");
						}else {
							clearInterval(resend);
							$me.removeAttr("disabled").html("\u77ed\u4fe1\u83b7\u53d6");
						}
					}, 1000);
				}else{
					var resend = setInterval(function(){
						count--;
						if (count > 0){
							$me.val("\u7b49\u5f85"+count+"\u79d2");
						}else {
							clearInterval(resend);
							$me.removeAttr("disabled").val("\u77ed\u4fe1\u83b7\u53d6");
						}
					}, 1000);
				}
			}else{
				if(params.way == 'button'){
					$me.removeAttr("disabled").html("\u77ed\u4fe1\u83b7\u53d6");
				}else{
					$me.removeAttr("disabled").val("\u77ed\u4fe1\u83b7\u53d6");
				}
			}
		},
	})
</script>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注