首页 > 编程开发 > JavaScript    日期:2018-09-30 / 来自互联网 / 浏览

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、在<head>和</head>引用js

<script type="text/javascript" src="http://domain.com/js/global.js"></script>

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

<script>hello()</script>

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章