Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<input id="tst" />
<input type="button" name="" value="Start" onmouseup="timer.start('tst');" />
<input type="button" name="" value="Stop" onmouseup="timer.stop('tst');" />
<input type="button" name="" value="Continue" onmouseup="timer.tick('tst');" />
<script type="text/javascript">
/*<![CDATA[*/
var timer={
init:function(id){
this[id]={
obj:document.getElementById(id)
}
},
start:function(id){
var obj=this[id];
obj.srt=new Date();
clearTimeout(obj.to);
this.tick(id)
},
stop:function(id){
clearTimeout(this[id].to);
},
tick:function(id){
this.stop(id);
var obj=this[id],sec=(new Date()-obj.srt)/1000,min=Math.floor(sec/60),sec=sec%60;
obj.obj.value=min+':'+(sec>9?sec:'0'+sec);
obj.to=setTimeout(function(){ timer.tick(id); },1000);
}
}
timer.init('tst');
/*]]>*/
</script>
</body>
</html>
Bookmarks