Home > Web Front-end > JS Tutorial > body text

Simple application method of timer

一个新手
Release: 2017-10-11 09:17:19
Original
1266 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template