标签:io ar java sp div on cti bs html
方法一:只要把下面的js放到你想要显示的地方就ok
setInterval("shijian.innerHTML=new Date().toLocaleString()+‘ 星期‘+‘日一二三四五六‘.charAt(new Date().getDay());",1000);
方法二:首先在body标签添加onload事件 :<body onload="dispDate()">。
var divGreet=document.getElementById("greet");这是获取要显示的标签的id,所以要在你要显示的地方加以一个标签 如:<span id="greet"></span>;
<script language="javascript"> | |
function dispDate() | |
{ | |
var date=new Date(); | |
var hour=date.getHours(); | |
var year=date.getYear(); | |
var month=date.getMonth(); | |
var day=date.getDate(); | |
var strDate; | |
var dayofWeek=date.getDay(); | |
//arrDays = [‘日‘,‘一‘,‘期二‘,‘三‘,‘四‘,‘五‘,‘六‘]; | |
//dayofWeek=arrDays[dayofWeek]; | |
strDate=year+"年"+month+"月"+day+"日"+" 星期"+dayofWeek; | |
//alert(hour); | |
var divGreet=document.getElementById("greet"); | |
if(hour>=6&&hour<12) | |
{ | |
divGreet.innerText="上午好!"+strDate; | |
} | |
if(hour>=12&&hour<=18) | |
{ | |
//var divGreet=document.getElementById("greet"); | |
divGreet.innerText="下午好!"+strDate; | |
//alert(divGreet.innerText); | |
} | |
if((hour>18&&hour<=23)||(hour>=0&&hour<6)) | |
{ | |
//var divGreet=document.getElementById("greet"); | |
divGreet.innerText="晚上好!"+strDate; | |
//alert(divGreet.innerText); | |
} | |
} | |
</script> |
标签:io ar java sp div on cti bs html
原文地址:http://www.cnblogs.com/costa92/p/4072465.html