<!DOCTYPE html> <html> <head> <title>setinterval.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script type="text/javascript"> function begintime() { timeID = setInterval("getTime()", 1000); } function getTime() { var date = new Date(); var day = date.getDay(); if (day == 0) { day = "日"; } var Localtime = date.getFullYear() + "年" + " " + date.getMonth() + "月 " + date.getDate() + "日 " + "星期 " + day + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "<br>"; document.getElementById("time").innerHTML = Localtime; document.getElementById("stoptime").style.display = "block"; document.getElementById("showTime").style.display = "block"; } function stoptime() { clearInterval(timeID); document.getElementById("stoptime").style.display = "none"; document.getElementById("showTime").style.display = "none"; } </script> </head> <body> This is my HTML page. <br> <br> <br> <input type="button" value="显示当前时间" onclick="begintime()"> <div style="border: 1px bule thin;width: 300px;height: 20px;" id="showTime"> <font id="time" color="red"></font> </div> <div style="display:none;" id="stoptime"> <input type="button" value="停止" onclick="stoptime()"> </div> </body> </html>
web页面实时显示系统时间,可隐藏。(供参考)