<script type="text/javascript">

//显示时间函数

var id;//设置该id主要是为了之后的暂停和取消显示时间用到clearInterval(这里传id);

function showTime(){

var divOne=document.getElementById("one");

var d=new Date();

var timStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+

d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+":"+d.getMilliseconds();

divOne.innerHTML=timStr;

id=setInterval(function(){

d=new Date();

timStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+

d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+":"+d.getMilliseconds();

divOne.innerHTML=timStr;

}, 1)

}

//暂停时间函数

function stopTime(){

clearInterval(id);

}

//取消显示时间函数

function cancelTime(){

var divOne=document.getElementById("one");

clearInterval(id);

divOne.innerHTML='';

}

</script>

</head>

<body>


<input type="button" value="显示时间"

οnclick="showTime()">

<input type="button" value="暂停时间"

οnclick="stopTime()">

<input type="button" value="取消时间"

οnclick="cancelTime()">

<div id="one"></div>

</body>