Js mainly use business logic to achieve, achieve results
Code:
<!DOCTYPE html> <!-- <html lang="en"> --> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <style> .start{ color: red; font-size: 16px; margin: 10px 0 0; } .totalTime{ width: 30px; } </style> </head> <body> <div> Please enter the countdown for how long: <the INPUT of the type = "text" the above mentioned id = "totalTime" class = "totalTime"> minutes ! <- <input type = " button" id = "start" value = " start the countdown"> -> <div the above mentioned id = "start1" class = "start"> start the countdown </ div> <HR> copy countdown for how long: <the INPUT of the type = "text" the above mentioned id = "totalTime1" class = "totalTime"> min <-! <input type = " button" id = "start" value = " start the countdown"> -> <div the above mentioned id = "start2" class = "start"> start the countdown </ div> <HR> copy How long countdown: <the INPUT of the type = "text" the above mentioned id = "totalTime3 "class =" totalTime "> min <-! <input type =" button "id =" start "value =" start the countdown "> -> <div the above mentioned id =" start3 "class =" Start "> start the countdown </ div> </ div> <script type="text/javascript"> window.onload = function () { // 第三个 var odiv3 = document.getElementById("start3"); var totalTime3 = 0; var time3 = 0; document.getElementById("start3").onclick = function () { clearInterval(time3) var number = parseInt($("#totalTime3").val() * 60 ) totaltime3 = number start3();//调用函数 varthe setInterval = Time (start3, 1000); // Set the timer is performed once every second time3 = Time the console.log (Time) } function start3 () { totaltime3 - var hour = totwo (the parseInt (totaltime3 / 3600)); // modulo time / 60/60 acquires (modulo conS is to obtain the position corresponding to decimal places) var min = totwo (the parseInt (totaltime3% 3600/60)); // modulo / 60 min acquired var S = totwo ( the parseInt (totaltime3% 60)); // the remainder of the total number of seconds taken var HTML + = hour "when" + min + "min" + s + "seconds" ; odiv3.innerHTML = HTML; // string add a div IF (totaltime3 <0) { // countdown function completes execution, there is play MP3 Alert ( "Time to ....." ) the clearInterval (time3); // To clear a function of time when executing the function } } // second a var odiv2 = document.getElementById ( "start2" ); var totalTime2 = 0 ; var TIME2 = 0 ; document.getElementById ( . "start2") the onclick = function () { the clearInterval (TIME2) var Number = the parseInt ($ ( " totalTime1 # "). Val () * 60 ) totaltime2= Number start2 (); // call the function var Time = the setInterval (start2, 1000); // Set the timer is performed once every second TIME2 = Time the console.log (Time) } function start2 () { totaltime2 - var hour totwo = (the parseInt (totaltime2 / 3600)); // time modulo / 60/60 acquires (modulo conS is to obtain the position corresponding to decimal places) var min = totwo (the parseInt (totaltime2% 3600/60)); // modulo / 60 min acquired var S = totwo (the parseInt (totaltime2% 60)); // the remainder of the total number of seconds taken var html = hour + "when" + min + "min" + s + "seconds" ; odiv2.innerHTML = HTML; // add the string into the div IF (totaltime2 <0) { // countdown function completes execution, where is playing MP3 Alert ( "time to ....." ) the clearInterval (TIME2); // to clear a function of time when executing the function } } // first var odiv = document.getElementById ( "Start1" ); var totalTime, 0 = ; var TIME1 = 0 ; function totwo (E) { return E <10? "0" + E: "" + E; //If the number is the number obtained by adding a 0 in front } document.getElementById ( "Start1"). The onclick = function () { the clearInterval (TIME1) var Number = the parseInt ($ ( "# totalTime,"). Val () 60 * ) totalTime = Number Start1 (); // call the function var time = the setInterval (Start1, 1000); // set the timer is performed once every second TIME1 = time the console.log (time) } function Start1 () { totalTime - var hour = totwo (the parseInt (totalTime / 3600)); // time modulo / 60/60 acquires (modulo obtain a position corresponding decimal conS) var min = totwo (the parseInt (totalTime% 3600/60)); // modulo / 60 min acquired var S = totwo (the parseInt (totalTime% 60)); // the remainder of the total number of seconds taken var HTML + = hour "when" + min + "min" + s + "seconds" ; odiv.innerHTML = HTML; // add the string into the div IF (totalTime <0) { // countdown function completes execution, there is play MP3 Alert ( "time to ....." ) the clearInterval (TIME1); // to clear a function of time when performing functions } } } </script> </body> </html>