很简单。。大家可以看下。代码如需:
<script type="text/javascript">
var now=(new Date()).getHours();
if(now>0&&now<=6){
document.write("午夜好,");
}else if(now>6&&now<=11){
document.write("早上好,");
}else if(now>11&&now<=14){
document.write("中午好,");
}else if(now>14&&now<=18){
document.write("下午好,");
}else{
document.write("晚上好,");
}
</script>