js问候-早上好、中午好、晚上好

1、在根目录(路径自己定义,我是图方便就放到了根目录)新建一个js文件(如:global.js),并复制下面代码放到到里面
//头部问候语
function hello() {
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=’夜深了,’}
var webUrl = webUrl;
document.write(‘ ‘+hello);
}

2、在和引用js

3、在和间合适的位置放入下面的代码
hello()

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注