JavaScript在浏览器标题栏上显示当前日期和时间的方法

时间:2021-05-26

本文实例讲述了JavaScript在浏览器标题栏上显示当前日期和时间的方法,分享给大家供大家参考。具体如下:

将这段脚本放到head区即可:

<script language="JavaScript"><!--function resetIt() {// Calculate Timevar timerID = null;var timerRunning = false;if(timerRunning) clearTimeout(timerID); timerRunning = false;// getTimevar timeNow = new Date();var hours = timeNow.getHours();var minutes = timeNow.getMinutes();var seconds = timeNow.getSeconds();var timeValue = "" + ((hours >12) ? hours -12 :hours)timeValue = ((timeValue <10)? "0":"") + timeValuetimeValue += ((minutes < 10) ? ":0" : ":") + minutestimeValue += ((seconds < 10) ? ":0" : ":") + secondstimeValue += (hours >= 12) ? " PM" : " AM"timerID = setTimeout("resetIt()",100);timerRunning = true;// getDatevar dateNow = new Date();var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');var date = ((dateNow.getDate()<10) ? "0" : "")+ dateNow.getDate();function y2k(number){return (number < 1000) ? number + 1900 : number;}// compileIttoday = timeValue + " " + days[dateNow.getDay()] + " " + months[dateNow.getMonth()] + ", " + date + " " + (y2k(dateNow.getYear())); if(document.all || document.getElementById){ // Browser Check document.title = today.toString(); }else{ self.status = today.toString(); // Default to status. }}resetIt();//--></script>

希望本文所述对大家的javascript程序设计有所帮助。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章