发送验证码60s倒计时

<!DOCTYPE html>
<html>
<head>
	<title>验证码60S倒计时</title>
	<style>

	.disable {
		pointer-events: none;
	}
</style>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
	<ul>
		<li class="tel"><input type="text" placeholder="手机号" name="member_phone"></li>
		<dl class="yzm">
			<dt><input type="text" placeholder="请输入验证码" name="auth_code"></dt>
			<div id="code" onclick="settime(this);"><ol >发送验证码</ol></div>
		</dl>
	</ul>
	<script type="text/javascript">
		//倒计时
		var countdown=60;
		var flag = false;
		function settime(val) {
			console.log(this.flag)
			if (countdown==60){
				sendSms()
			}
			if (countdown == 0) {
				$("#code").removeClass("disable");
				$("#code ol").text("获取验证码");
				countdown = 60;
				return false;
			} else {
				if (this.flag){
					$("#code").removeClass("disable");
					$("#code ol").text("获取验证码");
					flag=false;
					countdown=60;
					return  false;
				}
				$("#code").addClass("disable");
				val.value="重新发送(" + countdown + ")";
				$("#code ol").text("重新发送(" + countdown + ")")
				countdown--;
			}
			setTimeout(function() {
				settime(val);
			},1000);
		}

		function sendSms() {
			var  phone =$("[name='member_phone']").val();
			if (phone==''){
				flag=true;
				alert("手机号不能为空");
			}else{
				// ajax请求代码
			}
		}
	</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值