1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <title></title>5 <Scripttype= "Text/javascript">6 /*7 Timer periodically executes JS code8 */9 Ten //---------------------Method----------------------- One /* A 1. SetInterval (code, MILLISEC) - code:js code, usually JS function - millisec: Ms the returns a timer ID variable - */ - //Example 1: Automatically switch pictures - vararr= ["001.jpg", "002.jpg", "003.png"]; + varJ= 0; - varinterval; + A functionStartinterval () { at - //every 1s, call once startinterval () - interval=Window.setinterval ("changeimg ()", +); - } - - //Timer Start in functionchangeimg () { - to //get Element Object + varimgobj=document.getElementById ("Image"); - the //changing element Object information * imgobj.src= "images/" +arr[j%3] $ Panax Notoginseng J++; - if(J> 2) { the J= 0; + } A } the /* + 2. Clearinterval (timer) clears the Timer ID variable - Window.clearinterval (timer); $ */ $ //Timer End - functionStopinterval () { - Window.clearinterval (interval); the } - Wuyi </Script> the </Head> - <Body> Wu - <!--Timer - About <inputtype= "button"value= "Start Timer"onclick= "Startinterval ()"> $ <inputtype= "button"value= "Stop Timer"onclick= "Stopinterval ()"><BR/> - <imgID= "image"src= "Images/001.jpg" /> - - </Body> A </HTML>
<JavaScript> Eight. Timers