最近在写短信发送验证码,就写了个JS倒计时发送验证码按钮
- <script language="javascript" src="jquery-1.7.1.min.js"></script>
- <input type="button" id="btn" value="获取验证码"/>
- <script type="text/javascript">
- var wait = resetWait = 60;
- function timer(t) {
- if (wait == 0) {
- t.removeAttribute("disabled");
- t.value = "获取验证码";
- wait = resetWait;
- } else {
- t.setAttribute("disabled", true);
- t.value = "重新发送(" + wait + ")";
- wait--;
- setTimeout(function(){ timer(t) }, 1000);
- }
- }
- $("#btn").click(function () {
- timer(this);
- sendSMS(mobile, sendType);
- });
- function sendSMS(mobile, sendType){
- $.ajax({
- type: 'POST',
- url: '/verify/index',
- data: {mobile: mobile, type: sendType},
- success: function () {
- }
- });
- }
- </script>