一个简单的javascript时钟程序

javascript被称为没有剑柄的箭。

<html>
	<head> 
    <meta charset = "utf-8">
        <title>Koma Wong</title> 
            <script language="JavaScript">
                function date() {
                    days = new Array("星期日", "星期一", "星期二", 
                                     "星期三", "星期四", "星期五", 
                                     "星期六");
                    monthes = new Array("1", "2", "3", "4", "5", "6",
                                        "7", "8", "9", "10", "11", "12");
                    now = new Date();
                    year = now.getFullYear();	
                    month = now.getMonth();
                    date = now.getDate();
                    day = now.getDay();
                    dateStr = year + "年 " + monthes[month] + "月 " 
                                   + date + "日, " + days[day];
                    document.clock.date.value = dateStr;
                }
                function time() {
                    now = new Date();
                    hours = now.getHours();
                    minutes = now.getMinutes();
                    seconds = now.getSeconds();
                    timeStr = "" + hours + "时 ";
                    timeStr += ((minutes < 10) ? ":0" : ":") + minutes + "分 ";
                    timeStr += ((seconds < 10) ? ":0" : ":") + seconds + "秒 ";
                    document.clock.time.value = timeStr;
                }
                setInterval("time()", 1000); // 循环每秒定时调用
            </script>
    </head>TIME
        <body onLoad="date(); time();">
            <form name=clock>
                Date:<input type="text" name="date" size="20" value=""> <br/>
                Time:<input type="text" name="time" size="20" value=""> <br/>
            </form>
        </body>
</html>

效果:



猜你喜欢

转载自blog.csdn.net/rong_toa/article/details/80254306
今日推荐