html动态显示时间

注:setInterval和setTimeout的区别

setInterval是按照设置的时间无限次数的刷新

setTimeout是按照设置的时间值刷新一次

所以例二setTimeout实现了递归回调

<head>
    <title>无标题页</title>

    <script type="text/javascript">
   
   
    function sa()
    {
    var Time=new Date();
    document.getElementById("div").innerHTML=Time.getSeconds();
    }
   window.setInterval("sa()",1000);
    </script>

</head>
<body>
    <div id="div">
    </div>
</body>

====================================================================

或者

<head>
    <title>无标题页</title>

    <script type="text/javascript">
   
   
    function sa()
    {
    var Time=new Date();
    document.getElementById("div").innerHTML=Time.getSeconds();
    setTimeout("sa()",1000);
    }
   window.setTimeout("sa()",1000);
    </script>

</head>
<body>
    <div id="div">
    </div>
</body>

原文地址:https://www.cnblogs.com/happygx/p/1958052.html