状态栏的时间显示(javascript)

<html>
<head>
<script Language="JavaScript">
var timerID = null;//设置变量timeID,其为null数据类型。
var timerRunning = false;//设置变量timeRunning,其为布尔型。
function stopclock (){//定义一个函数。
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
  /*如果timeRunning的值是真,则取消延时操作,并将timeRunning的值设为假。*/
}
function showtime () {//定义一个函数,名为showtime。
        var now = new Date();//定义now为一个新的时间对象。
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
  /*分别定义变量hours,minutes,seconds的值为现在时间的小时,分,秒。*/
        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;//设置timerRunning 的值为真。
}
function startclock () {//定义一个函数startclock 。
        stopclock();
        showtime();
  /*调用startclock 函数和showtime函数。*/
}
</script>
</head>
<body onLoad="startclock()"><!--页面加载时,调用startclock()函数-->
</body>
</html> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值