用JS实现时间
在这里插入 <style> body{ background-color: #000; } #container{ color: brown; font-size:30px; background-color: cornflowerblue; border:2px solid rgb(245, 237, 237); height: 50px; width: 200px; } </style> </head> <body> <div id="container"></div> </body> <script> //获取对象 var oDiv = document.getElementById("container"); //将n变为两位数 function toDou(n){ if(n<10) n="0"+n; return n; } function showTime(){ var oData = new Date();//创建时间对象 var str=toDou(oData.getHours())+":"+toDou(oData.getMinutes())+":"+toDou(oData.getSeconds()); oDiv.innerHTML=str;//在浏览器中实现 } showTime(); //定时器 setInterval(showTime,1000); </script> </html>代码片