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)