📄 undertime.htm
字号:
<html>
<head>
<title>洪恩在线 - Javascript实例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../homepage.css">
<script Language="JavaScript">
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) ? " P.M." : " A.M."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad="startclock()">
<script language="Javascript" src="/pub/js/head.js"></script>
<table width="760" height="20" border=0 cellspacing="0" cellpadding="0" align="center" >
<tr bgcolor="CFDFFF">
<td height=20 class="p1" align="left"><img src="/pc/img/blank.gif" width="12" height="8"><font color="#000000"><font color="#FF9966">当前位置</font>:<a href="/default.htm" class="under">洪恩在线</a>
-> <a href="/pc/index.htm" class="under">电脑乐园</a> -> JavaScript实例</font></td>
</tr>
</table>
<table width="760" border=0 cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="207" valign="top"><img src="img/bule.gif" width="207" height="13"></td>
<td bgcolor="A8A8AB" width="1"><img src="img/blank.gif" width="1" height="1"></td>
<td align="right" height="22" width=530><img src="img/js.gif" width="186" height="20"></td>
<td width="22"><img src="img/blank.gif" width="1" height="1"></td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="124"><img src="img/blank.gif" width="1" height="1"></td>
<td background="img/line.gif" height="27" width=636><img src="img/blank.gif" width="1" height="1"></td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class=p3 align="center" width=711><b> 状态栏的时间显示</b></td>
<td class="p2" width="1" bgcolor="A8A8AB"><img src="img/blank.gif" width="1" height="1"></td>
<td class="p2" width="48"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" valign="top"> </td>
<td> </td>
<td bgcolor="5F74BF" width="28" align="center"><img src="img/bule1.gif" width="28" height="49"></td>
<td width="37" align="center"> </td>
</tr>
<tr>
<td align="center" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="5F74BF" align="center">
<td class="p1" align="right"><b><font color="#FFFFFF">效 果 演 示</font></b><font color="#FFFFFF">:</font></td>
<td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td class=p2 align="left" > <b><font color="#FF3333"><br>
请看下面的状态栏!</font></b> </td>
<td bgcolor="5F74BF" width="28" align="center"> </td>
<td width="37" align="center"> </td>
</tr>
<tr>
<td align="center" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="15"> </td>
</tr>
<tr align="center">
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="5F74BF" align="center">
<td class="p1" align="right"><b><font color="#FFFFFF">源代码如下</font></b><font color="#FFFFFF">:</font></td>
<td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="457" class="p2" valign="top"><b><br>
<br>
</b><span class="p1"><font color="#6633FF"> </font></span><b><br>
</b>
<form>
<p><span class="p1"><font color="#6633FF">这段程序放在<head>与</head>之间</font></span>
<textarea name="textarea3" onFocus="this.select()" onMouseOver="this.focus()" cols="50" rows="10" wrap="VIRTUAL" style="BACKGROUND-COLOR: #D5E9FD;" ><script Language="JavaScript">
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) ? " P.M." : " A.M."
window.status = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock () {
stopclock();
showtime();
}
</script></textarea>
</p>
<p><span class="p1"><font color="#6633FF">这段程序放在<body ****></font></span>
<textarea name="textarea" onFocus="this.select()" onMouseOver="this.focus()" cols="50" rows="2" wrap="VIRTUAL" style="BACKGROUND-COLOR: #D5E9FD;" >onLoad="startclock()"</textarea>
</p>
</form>
<b> </b></td>
<td bgcolor="5F74BF" width="28" align="center"> </td>
<td width="37" align="center"> </td>
</tr>
<tr>
<td align="center" valign="bottom" height="36">
<table width="238" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td>
<table width="110" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="5F74BF" align="center">
<td class="p1" align="right"><b><font color="#FFFFFF">源程序讲解:</font></b></td>
<td class="p1" width="11"><img src="img/bule2.gif" width="11" height="18"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="457" class="p2" valign="top" height="36"> </td>
<td bgcolor="5F74BF" width="28" align="center" height="36"><img src="img/bule1.gif" width="28" height="49"></td>
<td width="37" align="center" height="36"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="p2" align="right" width="693"> <br>
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolorlight="#666666" bordercolordark="#666666" class=p2>
<tr>
<td width="330">var timerID = null; <br>
</td>
<td width="430">设置变量timeID,其为null数据类型。</td>
</tr>
<tr>
<td width="330" bgcolor="CFDFFF">var timerRunning = false;<br>
</td>
<td width="430" bgcolor="CFDFFF">设置变量timeRunning,其为布尔型。</td>
</tr>
<tr>
<td width="330">function stopclock (){ <br>
</td>
<td width="430">定义一个函数。</td>
</tr>
<tr>
<td width="330" bgcolor="CFDFFF">if(timerRunning) <br>
clearTimeout(timerID);<br>
timerRunning = false; } <br>
</td>
<td width="430" bgcolor="CFDFFF">如果timeRunning的值是真,则取消延时操作,并将timeRunning的值设为假。</td>
</tr>
<tr>
<td width="330">function showtime () { <br>
</td>
<td width="430">定义一个函数,名为showtime。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">var now = new Date(); </td>
<td width="430">定义now为一个新的时间对象。</td>
</tr>
<tr>
<td width="330"> var hours = now.getHours(); <br>
var minutes = now.getMinutes(); <br>
var seconds = now.getSeconds() <br>
</td>
<td width="430">分别定义变量hours,minutes,seconds的值为现在时间的小时,分,秒。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">var timeValue = "" + ((hours >12) ? hours -12
:hours)<br>
</td>
<td width="430">定义变量timeValue的值为当小时数大于12时,则小时数减12。</td>
</tr>
<tr>
<td width="330">timeValue += ((minutes < 10) ? <br>
":0" : ":") + minutes <br>
</td>
<td width="430">设置timeValue的值为小时数加分钟数,当分钟数小于10时,前面加0。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">timeValue += ((seconds < 10) ? <br>
":0" : ":") + seconds<br>
</td>
<td width="430">设置timeValue的值为小时数加分钟数加秒数,当秒数小于10时,前面加0。</td>
</tr>
<tr>
<td width="330">timeValue += (hours >= 12) ? " P.M." : " A.M."<br>
</td>
<td width="430">设置timeValue的值为小时数加分钟数加秒数再加一个PM或AM。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">window.status = timeValue;<br>
</td>
<td width="430">在状态栏内显示timeValue的值。</td>
</tr>
<tr>
<td width="330">timerID = setTimeout("showtime()",1000);<br>
</td>
<td width="430">设置一个时间间隔,为1秒,每一个时间间隔调用一次showtime()函数。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">timerRunning = true; } <br>
</td>
<td width="430">设置timerRunning 的值为真。</td>
</tr>
<tr>
<td width="330">function startclock () <br>
</td>
<td width="430">定义一个函数startclock 。</td>
</tr>
<tr bgcolor="CFDFFF">
<td width="330">{ stopclock(); showtime(); }</td>
<td width="430">调用startclock 函数和showtime函数。</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
</td>
<td class="p2" width="18"> </td>
<td class="p2" width="1" bgcolor="A8A8AB"><img src="img/blank.gif" width="1" height="1"></td>
<td class="p2" width="48"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="5F74BF">
<td> </td>
</tr>
</table>
<p> </p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -