(js)获取60秒倒计时

(js)获取60秒倒计时

在有时候我们需要获取短信验证码的时候需要设置60秒的时间来获取手机的验证码。
js文件

	//发送验证码
	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)
    }

html文件

<input type="button" class="code-button" value="获取验证码" onclick="code_sned(this)" />
发布了101 篇原创文章 · 获赞 155 · 访问量 9364

猜你喜欢

转载自blog.csdn.net/qq_45163122/article/details/104562853