百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 帝国cms技术 » 正文

Js问候-早上好,中午好,晚上好

发布时间:2020-11-07

作品分类: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
   <script type="text/javascript" src="[!--news.url--]global.js"></script>


3、在<body>和间合适的位置放入下面的代码
   <script>hello()</script>
 

Top