您好,登錄后才能下訂單哦!
這篇文章主要介紹JavaScript如何實(shí)現(xiàn)輸入分鐘、秒倒計(jì)時(shí),文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
代碼如下:
<div class="container-fluid"> <div class="main-content-inner"> <div class="page-content"> <div class="page-header"> <form class="form-inline" id="searchform"> <div class="form-group" > <label>分</label> <input type="text" class="form-control" name="Minute" id="Minute"> </div> <div class="form-group" > <label>秒</label> <input type="text" class="form-control" name="Second" id="Second"> </div> <button type="button" class="btn btn-purple btn-sm" onclick="ok()"> 開(kāi)始 </button> </form> </div> <div class="row" > <p id="listview"></p> </div> </div> </div> </div>
<script> var t; var Minute; var Second; var d; function ok() { if ($("#Minute").val() == "0" || $("#Minute").val() == "") { Minute = 0; } else { Minute = $("#Minute").val(); } if ($("#Second").val() == "0" || $("#Second").val() == "") { Second = 0; } else { Second = $("#Second").val(); } var min = ""; if (Minute < 10) { min = "0" + Minute; } else { min = Minute + ""; } var sec = ""; if (Second < 10) { sec = "0" + Second; } else { sec = Second + ""; } $("#listview").text(min + ":" + sec); $(".page-header").hide(); $("#listview").show(); setTimeout(function () { begin() }, 1000); } function begin() { if (Second != 0) { Second--; min = ""; if (Minute < 10) { min = "0" + Minute; } else { min = Minute + ""; } sec = ""; if (Second < 10) { sec = "0" + Second; } else { sec = Second + ""; } $("#listview").text(min + ":" + sec); } else { if (Minute > 0) { Minute--; Second = 59; min = ""; if (Minute < 10) { min = "0" + Minute; } else { min = Minute + ""; } sec = ""; if (Second < 10) { sec = "0" + Second; } else { sec = Second + ""; } $("#listview").text(min + ":" + sec); } else { clearTimeout(t); } } t = setTimeout(function () { begin() }, 1000) } </script>
以上是“JavaScript如何實(shí)現(xiàn)輸入分鐘、秒倒計(jì)時(shí)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。