<html>
<script>
var stop;
var ss=0;
var s=0;
var m=0;
var h=0;
function clock(){
var btn = document.getElementById('start');
switch(btn.value){
case "start":
setTimeout("init()",10);
btn.value = "pause";
break;
case 'pause':
clearTimeout(stop);
btn.value = "start";
alert(document.getElementById("showtime").value);
break;
}
}
function init(){
ss++;
var show =document.getElementById("showtime");
if(m==60){
h++;m=0;
}
if(s==60){
m++;s=0;
}
if(ss==100){
s++;ss=0;
}
if(m<10&&s<10){
show.value= "0"+h+":"+"0"+m+":"+"0"+s+":"+ss;
}
else if(s<10&&m>=10){
show.value= "0"+h+":"+m+":"+"0"+s+":"+ss;
}else if(m<10&&s>=10){
show.value="0"+h+":"+"0"+m+":"+s+":"+ss;
}
else show.value= "0"+h+":"+m+":"+s+":"+ss;
stop=setTimeout("init()",10);
}
function reset(){
h=0;
m=0;
s=0;
ss=0;
document.getElementById("showtime").value="00:00:00:00";
clearTimeout(stop);
var btn = document.getElementById('start');
btn.value = "start";
}
</script>
<body onLoad="reset();">
<input type="text" id="showtime" name="showtime"/>
<input type="button" onclick="clock();" id="start" name="start" value="start"/>
<input type="button" onclick="reset();" id="reset" name="reset" value="reset"/>
<div id="01">
</div>
</body>
</html>
基本的功能已经写好,但是想在每次暂停之后自动记录时间。求解!
<script>
var stop;
var ss=0;
var s=0;
var m=0;
var h=0;
function clock(){
var btn = document.getElementById('start');
switch(btn.value){
case "start":
setTimeout("init()",10);
btn.value = "pause";
break;
case 'pause':
clearTimeout(stop);
btn.value = "start";
alert(document.getElementById("showtime").value);
break;
}
}
function init(){
ss++;
var show =document.getElementById("showtime");
if(m==60){
h++;m=0;
}
if(s==60){
m++;s=0;
}
if(ss==100){
s++;ss=0;
}
if(m<10&&s<10){
show.value= "0"+h+":"+"0"+m+":"+"0"+s+":"+ss;
}
else if(s<10&&m>=10){
show.value= "0"+h+":"+m+":"+"0"+s+":"+ss;
}else if(m<10&&s>=10){
show.value="0"+h+":"+"0"+m+":"+s+":"+ss;
}
else show.value= "0"+h+":"+m+":"+s+":"+ss;
stop=setTimeout("init()",10);
}
function reset(){
h=0;
m=0;
s=0;
ss=0;
document.getElementById("showtime").value="00:00:00:00";
clearTimeout(stop);
var btn = document.getElementById('start');
btn.value = "start";
}
</script>
<body onLoad="reset();">
<input type="text" id="showtime" name="showtime"/>
<input type="button" onclick="clock();" id="start" name="start" value="start"/>
<input type="button" onclick="reset();" id="reset" name="reset" value="reset"/>
<div id="01">
</div>
</body>
</html>
基本的功能已经写好,但是想在每次暂停之后自动记录时间。求解!
解决方案 »
- js 解析xml 跨浏览器
- JQUERY里面怎么获取Session的值或者后台public的变量。
- 【求助】jqGrid表格导航条里的添加删除按钮没有显示
- 用JavaScrip动态给按钮t添加事件
- varMenuObj.obj=varThisObj
- 急求JS函数转换C#函数(现金报酬)
- HTML编辑器怎样把焦点所在的文本是什么样式,比如:是粗体,粗体按钮就是按中的
- 取下拉菜单的值,语句怎么写?
- 模态窗口,我不要最大化和关闭(不要"口"和"X"出现)
- 求助各位大神,我想截取这两个页面中的中文内容, 请问怎么用一个正则提取出来?
- 急!关于视频播放的问题,求高手帮忙!
- 关于javascript的null和undefined!!!!!
$currenttime=$_POST["showtime"];
echo "下面是把变量currenttime的值存入文件还是存入库呢?";
?><html>
<script>
var stop;
var ss=0;
var s=0;
var m=0;
var h=0;
function clock(){
var btn = document.getElementById('start');
switch(btn.value){
case "start":
setTimeout("init()",10);
btn.value = "pause";
break;
case 'pause':
clearTimeout(stop);
btn.value = "start";
alert(document.getElementById("showtime").value);
document.myform.submit();
break;
}
}
function init(){
ss++;
var show =document.getElementById("showtime");
if(m==60){
h++;m=0;
}
if(s==60){
m++;s=0;
}
if(ss==100){
s++;ss=0;
}
if(m<10&&s<10){
show.value= "0"+h+":"+"0"+m+":"+"0"+s+":"+ss;
}
else if(s<10&&m>=10){
show.value= "0"+h+":"+m+":"+"0"+s+":"+ss;
}else if(m<10&&s>=10){
show.value="0"+h+":"+"0"+m+":"+s+":"+ss;
}
else show.value= "0"+h+":"+m+":"+s+":"+ss;
stop=setTimeout("init()",10);
}
function reset(){
h=0;
m=0;
s=0;
ss=0;
document.getElementById("showtime").value="00:00:00:00";
clearTimeout(stop);
var btn = document.getElementById('start');
btn.value = "start";
}
</script>
<body onLoad="reset();"><form method="POST" action="this.php" name="myform">
<input type="text" id="showtime" name="showtime"/>
<input type="button" onclick="clock();" id="start" name="start" value="start"/>
<input type="button" onclick="reset();" id="reset" name="reset" value="reset"/>
<div id="01">
</div>
</form> </body>
</html>
暂停的时候马上写cookie,把当前时间写入cookie,当你需要得知一共暂停了多久你只需要读取cookie内的时间并用其和现在的时间做比对即可,下边我给你提供一个我用jquery写的读写cookie的函数,或许对你有帮助 //擴展方法,讀寫cookie
//$.setCookie("a1","abc",999);寫
//aaa=$.getCookie("a1");讀
$.extend({getCookie:function(sName){
var aCookie=document.cookie.split("; ");
for(var i=0;i<aCookie.length;i++){
var aCrumb=aCookie[i].split("=");
if(sName==aCrumb[0]){return decodeURIComponent(aCrumb[1]);}
}
return '';
},setCookie:function(sName,sValue,sExpires){
var sCookie=sName+"="+encodeURIComponent(sValue);
if(sExpires!=null){sCookie+="; expires="+sExpires;}
document.cookie=sCookie;
},removeCookie:function(sName){
document.cookie=sName+"=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}});
<fieldset>
<legend>
秒表1
</legend>
<input onclick="startclock(0);" type="button" value="start">
<input onclick="haltclock(0);" type="button" value="halt">
<input onclick="stopclock(0);" type="button" value="stop">
<hr><div id="d0">00:00:00.00</div>
</fieldset>
</div><div style="width:200px;float:left">
<fieldset>
<legend>
秒表2
</legend>
<input onclick="startclock(1);" type="button" value="start">
<input onclick="haltclock(1);" type="button" value="halt">
<input onclick="stopclock(1);" type="button" value="stop">
<hr><div id="d1">00:00:00.00</div>
</fieldset>
</div><div style="width:200px;float:left">
<fieldset>
<legend>
秒表3
</legend>
<input onclick="startclock(2);" type="button" value="start">
<input onclick="haltclock(2);" type="button" value="halt">
<input onclick="stopclock(2);" type="button" value="stop">
<hr><div id="d2">00:00:00.00</div>
</fieldset>
</div><div style="width:200px;float:left">
<fieldset>
<legend>
秒表4
</legend>
<input onclick="startclock(3);" type="button" value="start">
<input onclick="haltclock(3);" type="button" value="halt">
<input onclick="stopclock(3);" type="button" value="stop">
<hr><div id="d3">00:00:00.00</div>
</fieldset>
</div><script language=javascript>
<!--var d, ss, s, m, h;
var sh = new Array(4);
var startTime = new Array(4);
var endTime = new Array(4);
var nowTime = new Array(4);
var tmpTime = new Array("","","","");
var flag = new Array(0,0,0,0);function timeShow(x){
d = new Date();
endTime[x] = d.getTime();
ss = Math.floor((endTime[x]-startTime[x])/10)%100;
s = Math.floor((endTime[x]-startTime[x])/1000)%60;
m = Math.floor((endTime[x]-startTime[x])/60000)%60;
h = Math.floor((endTime[x]-startTime[x])/3600000)%12;
ss<10?ss="0"+ss:ss;
s<10?s="0"+s:s;
m<10?m="0"+m:m;
h<10?h="0"+h:h;
nowTime[x] = h + ":" + m + ":" + s + "." + ss;
document.getElementById("d"+x).innerHTML = tmpTime[x] + nowTime[x];
}function startclock(x){
d = new Date();
startTime[x] = d.getTime();
if(!flag[x]){
sh[x] = setInterval("timeShow("+x+")",1);
flag[x] = 1;
}
}function haltclock(x){
if(flag[x]){tmpTime[x] += nowTime[x] + "<hr>";}
}function stopclock(x){
clearInterval(sh[x]);
flag[x] = 0;
tmpTime[x] = "";
}
//-->
</script>