<input type="text" id="textview"> <input type="button" value="start" onclick="start_button()"> <input type="button" value="end" onclick="end_button()"> function beging() { var date = new Date(); var hour = date.getHours(); var fen = date.getMinutes(); var miao = date.getSeconds(); var gettime = [hour,"时",fen,"分",miao,"秒"].join(""); var doc_text = document.getElementById("textview"); doc_text.value = gettime ; } //给定时器添加每秒自动获取时间 var ID ; function start_button() { if(ID===undefined){ beging(); ID = setInterval(beging,1000) } } //结束时间 function end_button() { clearInterval(ID); ID = undefined; }