JavaScript 之 验证码倒计时

实现按钮触发时间后,60秒之后可重新触发事件,并提供按钮60秒倒计时.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
        var i = 60;
        function timeChange() {
            document.getElementById("getCheckNum").value ="免费获取验证码("+i+")";
            if (i > 0) {
                i--;
            }
            else {
                $("getCheckNum").disabled = true;  //可用
            }
            window.setTimeout(function () { timeChange() }, 1000);
        }
    </script>
</head>
<body>
	<input type="button" onclick="timeChange();" id = "getCheckNum" value="获取验证码"/>
</body>
</html>

猜你喜欢

转载自648881556-qq-com.iteye.com/blog/1969620