Home > Web Front-end > JS Tutorial > JavaScript implements a method to display greetings based on time periods

JavaScript implements a method to display greetings based on time periods

怪我咯
Release: 2017-07-07 17:34:37
Original
5059 people have browsed it

This article mainly introduces the javascript method to display greetings according to time periods, involving the related operation skills of javascript time and string. Friends in need can refer to the following

The example in this article describes the method of using JavaScript to display greetings based on time periods. Share it with everyone for your reference. The specific implementation method is as follows:

Add the following code between in HTML:

<script language="javaScript">
<!--
now = new Date(),hour = now.getHours()
if(hour < 6){document.write("凌晨好!")}
else if (hour < 9){document.write("早上好!")}
else if (hour < 12){document.write("上午好!")}
else if (hour < 14){document.write("中午好!")}
else if (hour < 17){document.write("下午好!")}
else if (hour < 19){document.write("傍晚好!")}
else if (hour < 22){document.write("晚上好!")}
else {document.write("夜里好!")}
// -->
</script>
Copy after login

The above is the detailed content of JavaScript implements a method to display greetings based on time periods. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template