js 动态时间
效果如图:
- 页面HTML body中间放一个: <span id="gettime"></span>
- 复制下面JS到页面:
- <script type="text/javascript">
- function ShowTime() {
- var str = "";
- var time = new Date();
- var temp = time.toLocaleString();
- var day = time.getDay();
- switch (day) {
- case 1:
- str = "星期一";
- break;
- case 2:
- str = "星期二";
- break;
- case 3:
- str = "星期三";
- break;
- case 4:
- str = "星期四";
- break;
- case 5:
- str = "星期五";
- break;
- case 6:
- str = "星期六";
- break;
- case 0:
- str = "星期天";
- break;
- }
- document.getElementById("gettime").innerHTML = temp + " " + str;
- setTimeout(ShowTime, 1000);
- }
- onload = ShowTime;
- </script>