JavaScript如何实现输入分钟、秒倒计时
短信预约 -IT技能 免费直播动态提醒
这篇文章主要介绍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如何实现输入分钟、秒倒计时”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网行业资讯频道!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341