js实现页面时钟

<body onload="setInterval(nowtime,1000)">
    <form id="main" method="post" runat="server">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ebebeb">
        <tr>
            <td width="53%" height="63">
                <div align="center">
                    <table width="519" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="519">
                                <div align="left">
                                    <img src="../images/logoMain.gif" width="518" height="62" /></div>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
            <td width="47%" align="right">

                <script language="JavaScript">
                    today = new Date();
                    function initArray() {
                        this.length = initArray.arguments.length
                        for (var i = 0; i < this.length; i++)
                            this[i + 1] = initArray.arguments[i]
                    }
                    var d = new initArray(
     "星期日",
     "星期一",
     "星期二",
     "星期三",
     "星期四",
     "星期五",
     "星期六");
                    document.write(
     "",
     today.getYear(), "年",
     today.getMonth() + 1, "月",
     today.getDate(), "日   ",
     d[today.getDay() + 1],
     "");
                </script>

                &nbsp;<img align="absMiddle" src="../images/time.gif" />
                <span id="t1">

                    <script language="javascript">   

        todaytime1 = new Date();

        t1.innerText = todaytime1.getHours() + ‘:‘ + todaytime1.getMinutes() + ‘:‘ + todaytime1.getSeconds();

</script>

                </span>&nbsp;&nbsp;

                <script language="javascript">
                    function nowtime() {
                        todaytime = new Date();
                        t1.innerText = todaytime.getHours() + ‘:‘ + todaytime.getMinutes() + ‘:‘ + todaytime.getSeconds()
                    }
                </script>

            </td>
        </tr>
    </table>

</form>

</body>

效果:

时间自动走动

主要注意body中onload事件触发

js实现页面时钟,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。