JavaScript动态显示时间
<body> <div></div> <script> var div = document.querySelector('div'); retNowTime(); setInterval(retNowTime, 1000); function retNowTime() { var date = new Date(); var hours = date.getHours(); hours = hours < 10 ? '0' + hours : hours; var minutes = date.getMinutes(); minutes = minutes < 10 ? '0' + minutes : minutes; var seconds = date.getSeconds(); seconds = seconds < 10 ? '0' + seconds : seconds; div.innerHTML = hours + ':' + minutes + ':' + seconds; } </script> </body>