点击begin 开始,每个1s更新时间。点击stop后,时间停止。、
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title>Title</title> ???<script> ???????var ID; ???????function start(){ ???????????if (ID == undefined) { ???????????????foo(); ???????????????ID=setInterval(foo, 1000) ???????????} ???????} ???????function stop(){ ???????????clearInterval(ID); ???????????ID=undefined; ???????} ???????function foo(){ ??????????var date = new Date(); ??????????document.getElementById(‘timer‘).value=date.toLocaleString(); ???????} ???</script></head><body><input type="text" id="timer"><button onclick="start()">begin</button><button onclick="stop()">stop</button></body></html>
js 每1秒刷新一次时间——定时器
原文地址:http://www.cnblogs.com/snail280721764/p/7667743.html