这几天在浏览别人网站时,看着别人的网站可以显示当前日期及问候语,感觉很欢莘,想着要不自己也弄一个呗!!! 说弄咱就弄,下面介绍方法及代码。
1、将下面代码保存为date_hello.js。
function show_date_One(){ var enabled = 0; today = new Date(); var day; var date; if(today.getDay()==0) day = " 周日" if(today.getDay()==1) day = " 周一" if(today.getDay()==2) day = " 周二" if(today.getDay()==3) day = " 周三" if(today.getDay()==4) day = " 周四" if(today.getDay()==5) day = " 周五" if(today.getDay()==6) day = " 周六" show_date_week.innerHTML = day;} show_date_One(); function show_date_two(){ today=new Date(); var day; var date; var hello; hour=new Date().getHours(); if(hour < 6){ hello=' 凌晨好! ';}else if(hour < 9){ hello=' 早上好!';}else if(hour < 12){ hello=' 上午好!';}else if(hour < 14){ hello=' 中午好! ';}else if(hour < 17){ hello=' 下午好! ';}else if(hour < 19){ hello=' 傍晚好!';}else if(hour < 22){ hello=' 晚上好! ';}else{ hello='夜深了! ';}function GetCookie(sName) { var arr = document.cookie.match(new RegExp("(^| )"+sName+"=([^;]*)(;|$)")); if(arr !=null){return unescape(arr[2])}; return null; } var Guest_Name = decodeURIComponent(GetCookie('author')); var webUrl = webUrl;if (Guest_Name != "null" ){ hello = Guest_Name+' , '+hello+' 欢迎回来。'; } show_date_hello.innerHTML = ' '+hello;} show_date_two();
2、在需要显示的位置加入一下代码:
3、在
热评文章