您好,登錄后才能下訂單哦!
這篇文章主要介紹JavaScript如何實現輸入分鐘、秒倒計時,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
代碼如下:
<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()"> 開始 </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如何實現輸入分鐘、秒倒計時”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。