<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>根据当前时间显示问候语</title> </head> <body> <p><span>今天日期:</span><span id="span1"></span></p> <p><span>现在时间:</span><span id="span2"></span></p> <p id="p1"></p> <script> function wang() { var day= new Date(); var year = day.getFullYear();//年 var month = day.getMonth()+1;//月 var date = day.getDate(); //日 var hour = day.getHours();//时 var minutes = day.getMinutes(); //分 var mill = day.getSeconds();//秒 var hello = ""; //问候语 if (hour<=12){ hello = "上午好!欢迎来到贵美"; }else{ hello = "下午好!欢迎来到贵美"; } document.getElementById("span1").innerHTML=year+"年"+month+"月"+date+"日"; document.getElementById("span2").innerHTML=hour+"点"+minutes+"分"+mill+"秒"; document.getElementById("p1").innerHTML=hello; } wang() setInterval("wang()",1000) </script> </body> </html>
第二章2
最新推荐文章于 2021-11-23 12:12:00 发布