• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

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

JavaScript 水墨上仙 3165次浏览

JavaScript在浏览器标题栏上显示当前日期和时间,将这段脚本放到head区即可

<script language="JavaScript">
<!--

// ***********************************************
// http://www.75271.com
// ***********************************************

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) ? hours -12 :hours)
timeValue = ((timeValue <10)? "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) ? number + 1900 : number;}

// compileIt
today =  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在浏览器标题栏上显示当前日期和时间
喜欢 (0)
加载中……