JavaScript实现在标题栏上显示当前日期的方法
内容摘要
本文实例讲述了JavaScript实现在标题栏上显示当前日期的方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:<script language="JavaScript">
<!--
functio
复制代码 代码如下:<script language="JavaScript">
<!--
functio
文章正文
本文实例讲述了JavaScript实现在标题栏上显示当前日期的方法。分享给大家供大家参考。具体实现方法如下:
复制代码 代码如下:
<script language="JavaScript">
<!--
function writeIt() {
// getDate
var now = 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 = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// quadYear
function y2k(number){return (number < 1000) ? number + 1900 : number;}
// glueIt
today = days[now.getDay()] + " " +
months[now.getMonth()] + ", " +
date + " " +
(y2k(now.getYear())) ;
if(document.all || document.getElementById){ // Browser Check
document.title = today.toString();
}else{
self.status = today.toString(); // Default to status.
}
}
writeIt();
//-->
</script>
<!--
function writeIt() {
// getDate
var now = 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 = ((now.getDate()<10) ? "0" : "")+ now.getDate();
// quadYear
function y2k(number){return (number < 1000) ? number + 1900 : number;}
// glueIt
today = days[now.getDay()] + " " +
months[now.getMonth()] + ", " +
date + " " +
(y2k(now.getYear())) ;
if(document.all || document.getElementById){ // Browser Check
document.title = today.toString();
}else{
self.status = today.toString(); // Default to status.
}
}
writeIt();
//-->
</script>
希望本文所述对大家的javascript程序设计有所帮助。
代码注释