var timmerID = null;
function time() {
var time = documentgetElementById("now");
var left = documentgetElementById("left");
var t = timevaluesplit(":");
var hour = parseInt(t[0]);
var min = parseInt(t[1]);
min=min+1;
if(min==60){
hour=hour+1;
min=0;
if(hour==24){
hour=0;
}
}
timevalue=hour+":"+min;
leftvalue = leftvalue-1;
if(leftvalue==0){
mystop();
alert("时间已到!");
}
}
function mystart() {
var left = documentgetElementById("left");
leftvalue="40";
timmerID = windowsetInterval("time()", 100060);
}
function mystop() {
windowclearInterval(timmerID);
}
html页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN">
<html>
<head>
<title>timehtml</title>
<script type="text/javascript" src="funjs"></script>
</head>
<body>
时间起点:<input type="text" name="now" id="now" value="0:0"/><input type="button" value="开始" onclick="mystart();"><br>
剩余时间:<input type="text" name="left" id="left" value="40" disabled="disabled"/>分钟<br>
</body>
</html>
补充:这个javascript放在一个文件叫funjs,在html页面中要引用此文件,如:<script type="text/javascript" src="funjs"></script> ,注意不要把路径弄错了,src后面的路径按照实际的来,如果两个文件在一个目录下,就是如上这样引用,当然也可以直接把全部的js内容放在html文件的头部,如:<script type="text/javascript">
<!--javascript代码-->
</script>
我简单写了个 你看看
<head></head>
<body onload="time()">
<script type="text/javascript">
var count = 11;
function time(){
count--;
if(count <= 0){
count = 6;
time1();
return;
}
documentgetElementById('msg')innerHTML = '购买倒计时还剩0分'+count+'秒';
setTimeout(time,1000);
}
function time1(){
count --;
if(count <= 0){
count = 11;
time();
return;
}
documentgetElementById('msg')innerHTML = '付款倒计时还剩0分'+count+'秒';
setTimeout(time1,1000);
}
</script>
<div id="msg"></div>
</body><div id="seconds"></div>
<button id="startBtn">开始</button>
<script>
var maxTime=10,
startTime;
function timer(){
var passTime=(new Date()valueOf()-startTime)/1000;
if(passTime>=10){
passTime=10
documentgetElementById("seconds")innerText="000"
}else{
setTimeout(timer,20);
documentgetElementById("seconds")innerText=parseInt((maxTime-passTime)100)/100
}
}
documentgetElementById("startBtn")onclick=function(){
passTime=0;
startTime=new Date()valueOf();
timer()
}
</script>
虽然前面已经有高手回答了, 可毕竟我也写了, 就贴上吧
<!DOCTYPE html><html lang="en" xmlns=";
效果图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)