setInterval 方式
<script>
var sto;
function showTime(){
var date=new Date();
var hour=date.getHours();
var minute=date.getMinutes();
var second=date.getSeconds();
if(second<10){
second='0'+second;
}
if(hour<10){
hour='0'+hour;
}
document.getElementById('time').innerHTML='系统当前时间'+hour+':'+minute+':'+second;
sto=setTimeout('showTime()',1000);
}
function stopTime(){
clearTimeout(sto);
}
</script>
</head>
<body>
<input type="button" value="启动" οnclick="showTime()">
<input type="button" value="停止" οnclick="stopTime()"/>
<div id="time"></div>
</body>
setTimeout方式
<script>
var sto;
function showTime(){
var date=new Date();
var hour=date.getHours();
var minute=date.getMinutes();
var second=date.getSeconds();
if(second<10){
second='0'+second;
}
if(hour<10){
hour='0'+hour;
}
document.getElementById('time').innerHTML='系统当前时间'+hour+':'+minute+':'+second;
}
sto=setInterval('showTime()',1000);
function stopTime(){
clearTimeout(sto);
}
</script>
</head>
<body>
<input type="button" value="启动" οnclick="showTime()">
<input type="button" value="停止" οnclick="stopTime()"/>
<div id="time"></div>
</body>