var timer; $(document).ready(function(){ if (timer == undefined) timer = window.setInterval(showTime, 1000); }); //显示时间 function showTime() { var now = new Date(); document.getElementById("spanTime").innerHTML = now.toLocaleTimeString(); }