JavaScript计时器示例分析(2)


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JavaScript计时器</title>
        <input type="button" value="开始">
        <input type="button" value="暂停">
        <br>
    </head>
    <body>
        <script type="text/javascript">
            //定义打印方法
            function Print()
            {
                console.log("我在打印!");
            }
            var timer;//该值标识要取消的计时器执行代码块
            //开始打印
            function StartPrint()
            {
            timer=setInterval("Print()",1000);//开始计时器
            }
            //结束打印
            function StopPrint()
            {
                clearInterval(timer);;//取消计时器
            }
        </script>
    </body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfszw.html