在JavaScript 如何实现的简单时钟
1个回答
2013-10-19
展开全部
(1)在〈Head〉〈/Head〉之间放置以下脚本:
<script language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;
var id,pause=0,position=0;
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."
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock ()
{ stopclock();
showtime();
}
//-->
</script>
(2)在〈Body〉属性中加 onLoad="startclock()"
(3)在〈Body〉〈/Body〉中间加
<form name="clock" onSubmit="0">
<div align="center">
<center><p><input type="text" name="face" size="13" value></p></center>
</div>
</form>
即可。
<script language="JavaScript">
<!--
var timerID = null;
var timerRunning = false;
var id,pause=0,position=0;
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."
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock ()
{ stopclock();
showtime();
}
//-->
</script>
(2)在〈Body〉属性中加 onLoad="startclock()"
(3)在〈Body〉〈/Body〉中间加
<form name="clock" onSubmit="0">
<div align="center">
<center><p><input type="text" name="face" size="13" value></p></center>
</div>
</form>
即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询