<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取当前时间</title>
</head>
<body>
<input type="text" id="get_date">
<input type="button" id="start" value="开始">
<input type="button" id="stop" value="暂停">
<script>
var textEle=document.getElementById("get_date");
var start=document.getElementById("start");
var stop=document.getElementById("stop");
var t;
function f() {
var date_obj=new Date();
var date=date_obj.toLocaleString();
textEle.value=date;
}
f();
start.onclick=function f1() {
if (t===undefined){
t=setInterval(f,1000);
}
};
stop.onclick=function f2() {
clearInterval(t);
t=undefined;
};
</script>
</body>
</html>