梁某人

发展才是硬道理

导航

关于setInterval的用法

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
 <TITLE>setInterval Method</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
<META NAME="AUTHOR" CONTENT="InetSDK">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="ROBOTS" CONTENT="noindex">


<SCRIPT>
var oInterval="";
function fnStartInterval(){
 if(oInterval==""){
  oTimer.innerHTML="Interval Started";
  oInterval=window.setInterval("fnRecycle()",1000);
 }
 else{
  fnStopInterval();
 }
}
function fnStopInterval(){
 if(oInterval!=""){
  window.clearInterval(oInterval);
  oInterval="";
  oTimer.innerHTML="Interval Stopped";
 }
}
function fnRecycle(){
 var oDate=new Date();
 var sSwitch="am";
 var iHours=oDate.getHours();
 if(iHours>12){
  iHours-=12;
  sSwitch="pm";
 }
 var sMinutes=oDate.getMinutes() + "";
 if(sMinutes.length==1){
  sMinutes="0" + sMinutes;
 }
 var sSeconds=oDate.getSeconds() + "";
 if(sSeconds.length==1){
  sSeconds="0" + sSeconds;
 }
 oTimer.innerHTML=iHours + ":" + sMinutes + ":" + sSeconds + " " + sSwitch;


}
</SCRIPT>

<!-- SAMPLE_STYLE_START -->
<LINK REL="stylesheet" HREF="/workshop/basicSDKIE4.css"
TYPE="text/css">
<!-- SAMPLE_STYLE_END -->
</HEAD>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->

<BODY TOPMARGIN=0 LEFTMARGIN=0 BGPROPERTIES="FIXED" BGCOLOR="#FFFFFF"
LINK="#000000" VLINK="#808080" ALINK="#000000">
<BLOCKQUOTE CLASS="body">

<H1>setInterval Method</H1>
<P>The <b>setInterval</b> method invokes a function or line of code every time the specified amount of time passes.
In this sample, a function is called to update the <b>innerHTML</b> property of a <b>SPAN</b> with the current time every 1000 milliseconds, or every second.
Click Start Interval to invoke the <b>setInterval</b> method.
Click Stop Interval to remove the interval with the <b>clearInterval</b> method.
</P>
<SPAN ID=oTimer STYLE="font-size: 16pt; font-weight: bold; font-family: Times; color: #0000FF;">Interval Stopped</SPAN>
<P>

<INPUT TYPE=button VALUE="Start Interval" onclick="fnStartInterval()">
<INPUT TYPE=button VALUE="Stop Interval" onclick="fnStopInterval()">


<!-- START_PAGE_FOOTER -->
<BR><BR><BR>
&copy; <A CLASS="clsIncCpyRt" HREF="http://www.microsoft.com/isapi/gomscom.asp?TARGET=/info/cpyright.htm" TARGET="_top"> 2002 Microsoft Corporation. All rights reserved. Terms of use</A>.
<!-- END_PAGE_FOOTER -->
</BLOCKQUOTE>
</BODY>
</HTML>

posted on 2005-03-04 10:21  涛仔28  阅读(816)  评论(0编辑  收藏  举报