验证码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button>获取验证码</button>
    <script>
        var t
        var btn = document.querySelector('button')
        console.log(btn)
        btn.onclick = function () {
            btn.disabled = true
            btn.innerHTML = '10s倒计时'
            clearInterval(t)
            var count = 10
            t = setInterval(function () {
                count--
                btn.innerHTML = count + 's'
                if (count <= 0) {
                    clearInterval(t)
                    btn.disabled = false
                    btn.innerHTML = '10s倒计时'
                }
            }, 1000)
        }
    </script>
</body>

</html>

 

上一篇:JS大文件上传支持断点上传


下一篇:javaScripts的作用域问题