简单计时器

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <script>

            var i = 0;
            var start;

            window.onload = function(){

                document.getElementById("btn").onclick = function(){


                    start = setInterval("addTime()",1000);

                }


                document.getElementById("clo").onclick = function(){


                    clearInterval(start);
                }


            }


            function addTime(){

                i++;

                document.getElementById("show").innerHTML = i;

            }


        </script>

    </head>
    <body>

        <div id="show"></div>

        <button id="btn">计时开始</button>
        <button id="clo">计时终止</button>

    </body>
</html>

这里写图片描述

猜你喜欢

转载自blog.csdn.net/XianYuZong/article/details/78189613