Home >Web Front-end >JS Tutorial >JS implements the complete code to display the current time and date in the title bar of a web page_javascript skills

JS implements the complete code to display the current time and date in the title bar of a web page_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:34:191754browse

The example in this article describes the complete JS code to implement the current time and date in the title bar of a web page. Share it with everyone for your reference, the details are as follows:

This effect displays the current time and date at the front of the title bar of the web page. It can also display the day of the week and JS code. However, the code seems to have some compatibility issues. If it is IE, it will display normally. Other browsers You will not see the effect.

The screenshot of the running effect is as follows:

The online demo address is as follows:

http://demo.jb51.net/js/2015/js-title-show-date-time-codes/

The specific code is as follows:

<html>
<head>
<title>网页标题栏显示当前时间和日期的代码</title>
<script language="JavaScript1.2">
<!--hide
//定义月份的描述
var isnMonth = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
//定义星期的描述
var isnDay = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日");
//取得当前日期
today = new Date () ;
Year=today.getYear(); //取得日期的年份部分
Date=today.getDate(); //取得星期部分
//定义需要显示的字符串
titlestr="今天是: "+Year+"年"+isnMonth[today.getMonth()]+Date+"日"+isnDay[today.getDay()]
if (document.all) //检测浏览器兼容性,如果是IE则可以显示
document.title=titlestr //改变标题,显示日期。
//--hide-->
</script>
</head>
<body>
<b>请注意上面标题栏的时间</b>
</body>
</html>

I hope this article will be helpful to everyone in JavaScript programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn