相思资源网 Design By www.200059.com

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

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

<script language="JavaScript">
<!--
function resetIt() {
// Calculate Time
var timerID = null;
var timerRunning = false;
if(timerRunning)
  clearTimeout(timerID);
  timerRunning = false;
// getTime
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) "0":"") + timeValue
timeValue += ((minutes < 10) ":0" : ":") + minutes
timeValue += ((seconds < 10) ":0" : ":") + seconds
timeValue += (hours >= 12) " PM" : " AM"
timerID = setTimeout("resetIt()",100);
timerRunning = true;
// getDate
var 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) " " + 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程序设计有所帮助。

标签:
JavaScript,浏览器,标题栏,显示,当前,日期,时间,方法

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

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

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