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

来自:互联网
时间: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>
返回顶部
顶部