JavaScript实现动态时钟以及分时问候

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript实现动态时钟以及分时问候</title>
</head>
<body>
    <div id="time">
        </div><div id="timeShow"></div>
</body>
</html>
<script language="javascript">
     var t = null;
    t = setTimeout(time,1000);//开始执行
    function time()
    {
       clearTimeout(t);//清除定时器
       dt = new Date();
        h=dt.getHours();
        m=dt.getMinutes();
        s=dt.getSeconds();
       if(h < 6){document.getElementById("time").innerHTML =  "凌晨好";}
            else if (h < 9){document.getElementById("time").innerHTML =  "早上好";}
            else if (h < 12){document.getElementById("time").innerHTML =  "上午好";}
            else if (h < 14){document.getElementById("time").innerHTML =  "中午好";}
            else if (h < 17){document.getElementById("time").innerHTML =  "下午好";}
            else if (h < 19){document.getElementById("time").innerHTML =  "傍晚好";}
            else if (h < 22){document.getElementById("time").innerHTML =  "晚上好";}
            else {document.getElementById("time").innerHTML =  "夜里好";}
       document.getElementById("timeShow").innerHTML = "当前时间:"+h+"时"+m+"分"+s+"秒";
       t = setTimeout(time,1000); //
    }

  </script>
Last modification:February 24, 2018
If you think my article is useful to you, please feel free to appreciate