美文网首页
js基础3作业5

js基础3作业5

作者: HavenYoung | 来源:发表于2018-08-21 20:46 被阅读0次

短信倒计时

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>短信倒计时</title>
        <style type="text/css">
            #dinput {
                width: 100px;
                float: left;
            }
            
            #btnyz {
                width: 80px;
                float: left;
                display: block;
            }
            
            #reget {
                width: 80px;
                display: none;
                float: left;
            }
            
            #reyz {
                width: 80px;
                display: none;
                float: left;
            }
        </style>
    </head>

    <body>
        <input id="dinput" value="请输入验证码" />
        <button id="btnyz" onclick="getyz()">获取验证码</button>
        <div id="reget"></div>
        <button id="reyz" onclick="getyz()">重新获取</button>
    </body>

</html>
<script type="text/javascript">
    var obtnyz = document.getElementById('btnyz')
    var oreget = document.getElementById('reget')
    var oreyz = document.getElementById('reyz')
    var timer = null
    var count = 10

    function getyz() {
        obtnyz.style.display = 'none'
        oreyz.style.display = 'none'
        oreget.style.display = 'block'
        timer = setInterval(function() {
            count--
            oreget.innerHTML = count
            if(count == 0) {
                clearInterval(timer)
                count = 10
                oreget.style.display = 'none'
                oreyz.style.display = 'block'
            }
        }, 1000)
    }
</script>

相关文章

网友评论

      本文标题:js基础3作业5

      本文链接:https://www.haomeiwen.com/subject/rlksiftx.html