首先在body区域加入:οnlοad="showtime()"
然后在需要显示时间的地方加入:
或者将id="clock"加入到其他标签中
最后在网页中加入以下代码即可。
function showtime()
{
var nowTime = new Date();
var hours = nowTime.getHours();
var minutes = nowTime.getMinutes();
var seconds = nowTime.getSeconds();
var timer = " "+((hours>12)?hours-12:hours);
timer +=((minutes<10)?"0:":":")+minutes;
timer += ((seconds<10)?"0:":":")+seconds;
timer +=" "+((hours>12)?"pm":"am");
document.getElementById('cooo').innerHTML =timer;
setTimeout("showtime()",1000);
}
标签:
本文地址:如何在网页中加入当前时间的代码 https://www.shenqiu123.com/a/jianzhan/zhishi/4069.html