BOM Learning-javascript Timer Summary

Source: Internet
Author: User
Tags setinterval

<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title> Auto Growth Timer</title><Scripttype= "Text/javascript">  varAtime; functionclock () {var Time=NewDate (); Atime=time.gethours ()+":"+time.getminutes ()+":"+time.getseconds (); document.getElementById ("Clock"). Value=Atime; } setinterval (Clock, +); </Script></Head><Body><form><inputtype= "text"ID= "Clock"size= " the"style= "background: #000; color: #00ff00; width:55px"; /></form></Body></HTML>

Effect:

Show current time, auto grow

Add a timer for the button (for start and pause)

<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Timer</title><Scripttype= "Text/javascript">  varNum=0; vari; functionStartcount () {document.getElementById ('Count'). Value=num; Num=Num+1; I=SetTimeout ("Startcount ()", +); }  functionStopcount () {cleartimeout (i); }</Script></Head><Body>  <form>    <inputtype= "text"ID= "Count" />    <inputtype= "button"value= "Start"onclick= "Startcount ()"/>    <inputtype= "button"value= "Stop"onclick= "Stopcount ()" />  </form></Body></HTML>

Effect:

Click the Start button, counting from 0, one second plus 1. Click the button to stop and keep the current status.

Summarize:

1, SetInterval (Code, interaction time);

Parameter: Code: can be a function name or code string; interaction time: Setting the interaction time

Clearinterval (Id_from_setinterval);

Parameter: The ID value returned by SetInterval ().

2, SetTimeout (code, delay time);

Parameter: Code: can be a function name or code string; delay time: Set delay time

Cleartimeout (id_from_settimeout);

Parameter: The ID value returned by settimeout ().

BOM Learning-javascript Timer Summary

Related Article

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.