Countdown function in HTML (setinterval,clearinterval)

Source: Internet
Author: User

countdown to the main use of knowledge points : 1, set the time interval setinterval can be clearinterval canceled

2, milliseconds converted to time division format

  The following is the function in JS

var shijian=3600; var time=NULL; function Start () { time=setinterval ("Count ()", 1000);//return value time knowledge in order to need to be paused clearinterval (times) cleanup interval} function count () {if(shijian<0) {alert ("Time Out"); Pause ();//In general, this if condition is used for submitting data, here is just a test. }Else{            $("#time P"). html (Math.floor (SHIJIAN/60) + ":" +shijian%60);//This is used to convert milliseconds to time division formatshijian--;        Console.info (time);    }} function Pause () {clearinterval (time); } function GoOn () { time= SetInterval ("Count ()", 1000);//Reset time interval}

The second is HTML resources, in order to facilitate my CSS directly written in the HTML

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title>    <Scriptsrc= "1.js"></Script>    <Scriptsrc= "Jquery-1.8.3.min.js"></Script>    <styletype= "Text/css">input{Background-color:#9fc5f1;width:100px;Height:30px;Line-height:30px;text-align:Center;Color:#fff;font-size:14px;Font-weight:Bold;        }#time P{Color:#1f6dc2;font-size:48px;Font-weight:Bold;Margin-left:90px;Margin-bottom:0px;        }    </style>    <Linkrel= "stylesheet"href= "Https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"Integrity= "Sha384-bvyiisifek1dgmjrakycuhahrg32omucww7on3rydg4va+pmstsz/k68vbdejh4u"Crossorigin= "Anonymous"><Body><DivID= "Time">    <P>00:00</P>    <inputtype= "button"value= "Start"onclick= "Start ()"/>    <inputtype= "button"value= "Paused"onclick= "Pause ()"/>    <inputtype= "button"value= "Continue"onclick= "GoOn ()"/></Div></Body></HTML>

Small partners who need code can download their own

Link: http://pan.baidu.com/s/1boZ8Xun Password: ymu0

Countdown function in HTML (setinterval,clearinterval)

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.