用JS+div在页面指定位置写一个电子时钟

来源:互联网 发布:网络链接不上 编辑:程序博客网 时间:2024/05/17 06:16
<!DOCTYPE html><html>    <title>电子时钟</title></head><body>    <!--设置时钟的样式-->    <div id = "myclock" style="font-size: 36px;color: brown;font-weight: bold"></div></body><script>    setInterval("showClock()",1000);//获取定时器,每1000毫秒刷新一次function方法    function showClock(){        t = new Date();        h = t.getHours();        m = t.getMinutes();        s = t.getSeconds();        clock = (h >= 12) ? "下午":"上午";        h = (h > 12) ? h-12 :h;        h = (h < 10) ? "0" + h : h;        m = (m < 10) ? "0" + m : m;        s = (s < 10) ? "0" + s : s;        myclock.innerHTML = clock + "" + h + ":" + m + ":" + s;    }</script></html>

这里写图片描述

原创粉丝点击