zoukankan      html  css  js  c++  java
  • JavaScript模拟网页时钟

    • window.setInterval("要执行的函数",毫秒数)
      • 每隔多少毫秒执行一次函数
    • window.clearInterval()
      • 停止
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script>
                var demo = null;
                
                function nowTime(){
                    // 获取当前时间
                    var showTime =  Date().toLocaleString();
                    console.log(showTime)
                    // 让div上面显示的文本是获取到的当前时间
                    document.getElementById("timeDiv").innerHTML= showTime;
                }
                function start(){
                    // 每隔1S执行一次nowTime函数,用户动态显示时间
                    demo = window.setInterval("nowTime()",1000);
                }
                function stop(){
                    window.clearInterval(demo);
                }
            </script>
        </head>
        <body>
            <div id="timeDiv"></div>
            <input type="button" value="启动" onclick="start()" />
            <input type="button" value="停止" onclick="stop()" />
        </body>
    </html>
  • 相关阅读:
    强大的异或运算-深度好文
    40-3Sum Closest
    39-Remove Duplicates from Sorted Array
    谈谈AI
    38- Majority Element
    37-Invert Binary Tree
    36-Same Tree
    35-Remove Element
    34. Swap Nodes in Pairs
    33. Implement strStr()
  • 原文地址:https://www.cnblogs.com/zhangzhixi/p/14312712.html
Copyright © 2011-2022 走看看