jQuery实现倒计时重新发送短信验证码功能示例

2020-05-24 21:42:09易采站长站整理

本文实例讲述了jQuery实现倒计时重新发送短信验证码功能的方法。分享给大家供大家参考,具体如下:


<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var countdown=60;
function settime(obj) {
if (countdown == 0) {
obj.removeAttribute("disabled");
obj.value="免费获取验证码";
countdown = 60;
return;
} else {
obj.setAttribute("disabled", true);
obj.value="重新发送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}
</script>
<body>
<input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" />
</body>
</html>

实践例子:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>抢占iPhone7专属预订名额</title>
<link rel="stylesheet" href="getiphone.css" />
</head>
<body style="width: 100%;height: 100%;background:#fff url(iponeImg/beijing.png) no-repeat center fixed;background-size:100% 100%;text-align: center;">
<div class="top">
<img src="iponeImg/wenan.png" />
</div>
<h1 class="title"><span></span>上市时间同步发售<span></span><br />首批新苹果30个预订专属名额</h1>
<form id="activityForm" class="form-horizontal" method="post" action="/wamei/activityController/save.htm">
<label>
<span><img src="iponeImg/yonghu.png" /></span>
<i></i>
<input type="text" class="inline-input" id="name" name="name" placeholder="请输入您的真实姓名" datatype="*1-20" errormsg="姓名最多20个中英文字符!" nullmsg="请输入您的真实姓名!" />
</label>
<label>
<span><img src="iponeImg/dianhua.png" /></span>
<i></i>
<input type="text" class="inline-input" id="mobilePhone" name="mobilePhone" placeholder="请输入您的手机号码" datatype="*" errormsg="请输入您的手机号码!" nullmsg="请输入您的手机号码!" />
</label>
<label>
<span><img src="iponeImg/yanzhengma.png" /></span>
<i></i>
<input type="text" id="validateCode" class="inline-input" name="validateCode" placeholder="验证码" datatype="*" errormsg="请输入验证码!" nullmsg="请输入验证码!" style="width:180px;" />