<JavaScript> Eight. Timers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.