JavaScript输入分钟、秒倒计时技巧总结(附代码)

这篇文章主要介绍了JavaScript输入分钟、秒倒计时的代码实现,通过css和js代码展示了逻辑过程,具体操作步骤大家可查看下文的详细讲解,感兴趣的小伙伴们可以参考一下。

代码如下:

<div> <div> <div> <div> <form> <div> <label>分</label> <input type="text"> </div> <div> <label>秒</label> <input type="text"> </div> <button type="button"> 开始 </button> </form> </div> <div> <p></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>

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助~如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持!

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydzgf.html