Home >Web Front-end >JS Tutorial >Simple application method of timer

Simple application method of timer

一个新手
一个新手Original
2017-10-11 09:17:191301browse

Here we implement the related operations of starting and pausing the timer

    <script>
        var i = 0;
        var start;
        window.onload = function(){
            document.getElementById("red").onclick = function(){
                start = window.setInterval("time()",1000);//计时器

            }


            document.getElementById("mom").onclick = function(){
                window.clearInterval(start);
            }

        }
        function time(){
                i++;
                document.getElementById("display").innerHTML = i;
            }

    </script>
</head>
<body>
    <p id="display"></p>
    <button id="red">掀起你的盖头来~~~~~</button>
    <button id="mom">啊,妈呀!!!</button>
</body>

The above is the detailed content of Simple application method of timer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use window.onloadNext article:How to use window.onload