本文實例講述了javascript實現(xiàn)根據(jù)時間段顯示問候語的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
將以下代碼加入HTML 的<body></body>之間:
<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>希望本文所述對大家的javascript程序設(shè)計有所幫助。
新聞熱點
疑難解答