當前位置:首頁文章首頁 IT學院 IT技術

狀態(tài)欄上時鐘的代碼

作者:  來源:  發(fā)布時間:2011-5-26 15:25:24  點擊:

本文章提供給大家的是一個學習實例,關于如何在狀態(tài)上顯示時鐘,把下面代碼放進<body>中就可運行,趕緊來試下吧。

<BODY onLoad="startclock()">
<SCRIPT LANGUAGE=java script>
<!--
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
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 += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM." : " AM."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
-->
</SCRIPT>

文章評論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z