比较简单,直接贴上代码:
<!
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 > clock </ title >
< script type ="text/javascript" >
var enable = 0 ,tm;
function setTime(){
var now = new Date();
var time = now.toLocaleString();
document.getElementById( " time " ).value = time;
tm = setTimeout( " setTime() " , 1000 );
enable = 1 ;
}
</ script >
</ head >
< body >
< input type ="text" id ="time" style ="overflow:visible" value ="" />
< input type ="button" value ="开" onclick ="if(enable==0){setTime();}" />
< input type ="button" value ="关" onclick ="if(enable==1){time.value='';clearTimeout(tm);enable=0}" />
</ body >
</ html >
"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 > clock </ title >
< script type ="text/javascript" >
var enable = 0 ,tm;
function setTime(){
var now = new Date();
var time = now.toLocaleString();
document.getElementById( " time " ).value = time;
tm = setTimeout( " setTime() " , 1000 );
enable = 1 ;
}
</ script >
</ head >
< body >
< input type ="text" id ="time" style ="overflow:visible" value ="" />
< input type ="button" value ="开" onclick ="if(enable==0){setTime();}" />
< input type ="button" value ="关" onclick ="if(enable==1){time.value='';clearTimeout(tm);enable=0}" />
</ body >
</ html >
![1.BMP](https://i-blog.csdnimg.cn/blog_migrate/8ce3397d365bc904d42dbb7bd3e9c72a.bmp)