侧边栏壁纸
  • 累计撰写 611 篇文章
  • 累计收到 0 条评论

js 短信60秒倒计时

加速器之家
2024-08-22 / 0 评论 / 3 阅读 / 正在检测是否收录...

Javascript 实现 点击按钮 倒计时60秒方可再次点击发送的效果

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <a href="javascript:void(0);" id="gSMS" onclick="get_sms_captcha('2')">获取短信验证码</a> 
</body>
</html>

Javascript代码:

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)
    }
}

效果图:

image.png

0

评论

博主关闭了当前页面的评论