如何在我的网页标题中显示今天的日期?

时间:2014-04-26 22:36:26

标签: javascript html

我试图在我的网页标题中显示今天的日期。但是,我尝试使用下面的脚本,但它没有用。该脚本适用于页面正文。我应该使用不同的脚本吗?

<script><!-- 
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday");
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");
var now = new Date();
document.write(dayNames[now.getDay()] + ", " + 
monthNames[now.getMonth()] + " " + 
now.getDate() + ", " + now.getFullYear());

// -->
</SCRIPT>

1 个答案:

答案 0 :(得分:1)

尝试

document.title=new Date();

您还可以保留大部分旧脚本,并将document.write( stuff );更改为document.title = stuff;