js 短信60秒倒计时

废话不多说,看代码。

这是获取短信的按钮

<a href="javascript:void(0);" id="gSMS" onclick="get_sms_captcha(‘2‘)" style="font-size: 0.6rem;color: #444;left: 0.5rem;">获取短信验证码</a> 

下面是js代码,思想就是定义60的数,然后定时器设置为一秒,每一秒执行一次。等到0是就可以重新获取短信验证码。

var countDownT = 60;
function get_sms_captcha(type){
    countDownT = 60;
    setTime();
    //下方写业务
}

function  setTime(){
    if (countDownT == 0){
        $("#gSMS").attr("onclick","get_sms_captcha(‘2‘)");
        $("#gSMS").text("获取短信验证码");
    } else{
        $("#gSMS").attr("onclick","#");
        $("#gSMS").text("重新发送("+countDownT+")");
        countDownT--;
        setTimeout(function () {
            setTime();
        },1000)
    }
}

原文地址:https://www.cnblogs.com/zhengxq21/p/9689773.html

时间: 2024-08-09 06:21:48

js 短信60秒倒计时的相关文章

yii框架实现注册页面短信验证60秒倒计时

先说下简单的,直接用jquery来实现短信验证60秒倒计时,然后在说明在yii框架下怎么实现的. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

js实现60秒倒计时效果(使用了jQuery)

今天碰到要实现一个类似那种短信验证码60秒倒计时的需求,好久不写js,有点手生.把代码记录下,方便后续查阅. 这里我用了jQuey,毕竟写起来简洁点.下面直接看效果和代码. 一.效果 二.代码 (1)html <input type="button" id="btn" value="免费获取验证码" onclick="daojishi(10,this)" /> 注意:要引入JQuery (2)js <scri

js jquery 按钮点击后 60秒之后才能点击 60秒倒计时

var wait = 60; function time(o) { if (wait == 0) { $(o).attr("disabled", false); $(o).val("获取验证码"); wait = 60; } else { $(o).attr("disabled", true); o.val(wait + "秒后重新发送"); wait--; setTimeout(function () {time(o);},

点击按钮出现60秒倒计时js代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

验证码60秒倒计时

验证码60秒倒计时(jQuery), 代码如下: //验证码倒计时 var countdown = 60; var st; function settime(element) { if (countdown != 0) { st = setTimeout(function () { settime(element); }, 1000); } if (countdown == 0) { element.removeAttr("disabled"); element.val("获

淘宝60秒倒计时

<!DOCTYPE html> <html> <head> <title>60秒倒计时</title> <script type="text/javascript"> window.onload=function(){ var oBtn = document.getElementById('but'); var conut = 60; var timer = null; oBtn.onclick=function(

JS——实现短信验证码的倒计时功能(没有验证码,只有倒计时)

1.功能描述 当用户想要获取验证码时,就点击 免费获取验证码 ,然后开始倒计时,倒计时期间按钮文字为剩余时间x秒,且不可按状态,倒计时结束后,按钮更改为点击重新发送. 2.分析 必须用到定时器.按钮点击后,在定时器内做出判断.倒计时60秒,到0结束. 3.代码实现: 重点介绍:定时器在进行下一次倒计时之前,一定要清除一下,这样的话保证下一次定时器倒计时是正常的. <!DOCTYPE html> <html> <head> <meta charset="U

js 短信验证码倒计时效果

<div class="input-group" id="login_do"> <input type="num" class="form-control inputD" id="telCode" placeholder="短信验证码"/> <span class="input-group-addon input-span-black" 

js短信验证倒计时

<!DOCTYPE html><html> <head>  <meta charset="UTF-8">  <title></title>  <style type="text/css">   *{    margin: 0;    padding: 0;   }   button{    width: 100px;   }  </style>  <script t