javascript的:<!-- Time-->
<html>
<head>
<title>Time</title>
<style>
body { border: 0; background-color: buttonface; color: black; margin: 3px,0,0,0 }
.clocktxt { font-family: Arial; font-weight: normal; font-size: 8pt }
#btnsd { border: 2px groove white; background-color: buttonface; font-family: verdana; font-size: 9px }
</style>
<script language="JavaScript">
//Clock Script
var showclock;
function init(){
showdate()
showclock=true;
}
function showdate(){
//edit refresh rate here
var refreshrate=1000; var Clock=new Date()
var hours=Clock.getHours()
var minutes=Clock.getMinutes()
var seconds=Clock.getSeconds() var dn="AM"
if (hours>12){
dn="PM"
hours=hours-12
} if (hours==0) hours=12
if (minutes<=9) minutes= "0" + minutes
if (seconds<=9) seconds= "0" + seconds //edit format here
format = hours+":"+minutes+":"+seconds+" "+dn; Time.innerHTML=format;
if (showclock==false) Time.innerHTML="<input type='button' value='Sh.time' id='btnsd' title='Show time'>"
else
setTimeout("showdate()",refreshrate)
}
</script>
</head>
<body scroll="no" onLoad="init()">
<center>
<font class="clocktxt"> <span id="Time" style="position:center;"></span></font>
<h1>test text!!!</h1>
</body>
</html>
<html>
<head>
<title>Time</title>
<style>
body { border: 0; background-color: buttonface; color: black; margin: 3px,0,0,0 }
.clocktxt { font-family: Arial; font-weight: normal; font-size: 8pt }
#btnsd { border: 2px groove white; background-color: buttonface; font-family: verdana; font-size: 9px }
</style>
<script language="JavaScript">
//Clock Script
var showclock;
function init(){
showdate()
showclock=true;
}
function showdate(){
//edit refresh rate here
var refreshrate=1000; var Clock=new Date()
var hours=Clock.getHours()
var minutes=Clock.getMinutes()
var seconds=Clock.getSeconds() var dn="AM"
if (hours>12){
dn="PM"
hours=hours-12
} if (hours==0) hours=12
if (minutes<=9) minutes= "0" + minutes
if (seconds<=9) seconds= "0" + seconds //edit format here
format = hours+":"+minutes+":"+seconds+" "+dn; Time.innerHTML=format;
if (showclock==false) Time.innerHTML="<input type='button' value='Sh.time' id='btnsd' title='Show time'>"
else
setTimeout("showdate()",refreshrate)
}
</script>
</head>
<body scroll="no" onLoad="init()">
<center>
<font class="clocktxt"> <span id="Time" style="position:center;"></span></font>
<h1>test text!!!</h1>
</body>
</html>
类文件Clock.class于html文件放在同一目录下。
function scroll()
{
dt=new Date();
sec=dt.getSeconds();
hr=dt.getHours();
ampm="A.M.";
smin=dt.getMinutes();
if (hr >=12) ampm="P.M.";
if (hr > 12) hr -=12;
if (smin <= 9) smin = "0"+smin;
if (sec <= 9) sec = "0"+sec;
if (hr <= 9) hr = "0"+hr;
var scroller="当前时间:"+hr+":"+smin+":"+sec+" "+ampm;
var timeout=setTimeout("scroll()", 1000);
clock.innerText=scroller;
}
</script>
<table><tr><td id=clock>
<script>scroll()</script>
var timerID = null;
var timerRunning = false; function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var year = now.getYear();
var month= now.getMonth()+1;
if (month<10)
month = "0" + month;
var days = now.getDate();
if (days<10)
days = "0" +days;
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) ? " P.M. " : " A.M. "
timeValue += "版权所有,不得翻录,违者必究";
window.status = year+"-"+month+"-"+days+" "+timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
</script>
<script language="javascript">
startclock();
</script>