JS代码编写倒计时120分钟要求确切到时、分、秒。
<scripttype="text/javascript">varsec=60,min=60;hour=1;varhou=0;flag=0;idt=window.setT...
<script type="text/javascript">
var sec = 60,min=60;
hour = 1;
var hou = 0; flag = 0;
idt = window.setTimeout("ls();", 1000);
function ls() {
sec--;
min = 60;
if (sec == 0)
{ sec = 60;min -= 1; }
if (min == 60&&hour==0)
{ min = 0; hour -= 1; }
if (min == 0&&sec==0)
{min = 60;hour -= 1;}
if(min>0) {
min--;
// }
document.getElementById("rest_time").innerText = hour + ":" + min + ":" + sec;
idt = window.setTimeout("ls();", 1000);
if (hour==0&&min==0&&sec==1) { document.getElementById("btn_ok").click();
alert('考试时间已到,试卷已提交,感谢使用本系统!'); }
}
</script>
运行出来时间不对。。。分钟部分总从59再跳到60min 展开
var sec = 60,min=60;
hour = 1;
var hou = 0; flag = 0;
idt = window.setTimeout("ls();", 1000);
function ls() {
sec--;
min = 60;
if (sec == 0)
{ sec = 60;min -= 1; }
if (min == 60&&hour==0)
{ min = 0; hour -= 1; }
if (min == 0&&sec==0)
{min = 60;hour -= 1;}
if(min>0) {
min--;
// }
document.getElementById("rest_time").innerText = hour + ":" + min + ":" + sec;
idt = window.setTimeout("ls();", 1000);
if (hour==0&&min==0&&sec==1) { document.getElementById("btn_ok").click();
alert('考试时间已到,试卷已提交,感谢使用本系统!'); }
}
</script>
运行出来时间不对。。。分钟部分总从59再跳到60min 展开
1个回答
展开全部
试试这个,看满不满足你要求
<script type="text/javascript">
var sec =60,min=59,hour = 1;
var idt = window.setInterval("ls();", 1000);
var format = function(str){
if(parseInt(str) < 10){
return "0" + str;
}
return str;
};
function ls() {
sec--;
if(sec == 0){
min--;
sec = 59;
}
if(min < 0 && hour > 0){
hour--;
min = 59;
}
document.getElementById("rest_time").innerText = format(hour) + ":" + format(min) + ":" + format(sec);
if (parseInt(hour)==0&&parseInt(min)==0&&parseInt(sec)==0) {
window.clearInterval(idt);
//document.getElementById("btn_ok").click();
alert('考试时间已到,试卷已提交,感谢使用本系统!');
}
}
</script>
<script type="text/javascript">
var sec =60,min=59,hour = 1;
var idt = window.setInterval("ls();", 1000);
var format = function(str){
if(parseInt(str) < 10){
return "0" + str;
}
return str;
};
function ls() {
sec--;
if(sec == 0){
min--;
sec = 59;
}
if(min < 0 && hour > 0){
hour--;
min = 59;
}
document.getElementById("rest_time").innerText = format(hour) + ":" + format(min) + ":" + format(sec);
if (parseInt(hour)==0&&parseInt(min)==0&&parseInt(sec)==0) {
window.clearInterval(idt);
//document.getElementById("btn_ok").click();
alert('考试时间已到,试卷已提交,感谢使用本系统!');
}
}
</script>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询