BLOGJAVA

状态栏显示当前时间

<html>
<head>
<script Language="JavaScript">
var timerID = null;
var timerRunning = false;
function stopclock (){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
/*如果timeRunning的值是真,则取消延时操作,并将timeRunning的值设为假。*/
}
function showtime () {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();

        var timeValue = "" + ((hours >12) ? hours -12 :hours)//定义变量timeValue的值为当小时数大于12时,则小时数减12。
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes//设置timeValue的值为小时数加分钟数,当分钟数小于10时,前面加0。
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds//设置timeValue的值为小时数加分钟数加秒数,当秒数小于10时,前面加0。
        timeValue += (hours >= 12) ? " P.M." : " A.M."//设置timeValue的值为小时数加分钟数加秒数再加一个PM或AM。
        window.status = timeValue;//在状态栏内显示timeValue的值。
        timerID = setTimeout("showtime()",1000);//设置一个时间间隔,为1秒,每一个时间间隔调用一次showtime()函数。
        timerRunning = true;
}
function startclock () {
        stopclock();
        showtime();
}
</script>
</head>
<body onLoad="startclock()">
</body>
</html>

posted on 2008-05-13 10:56 七页 阅读(123) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: