js根据时间变成自动更新
<script type="text/javascript">
day = new Date( )
hru = day.getHours( )
miu = day.getMinutes( )
mi = miu/60
hr = hru+mi
if (( hr >= 0 ) && (hr < 1.5 ))tim="0"
if (( hr >= 1.5 ) && (hr < 3 ))tim="-64"
if (( hr >= 3 ) && (hr < 4.5 ))tim="-128"
if (( hr >= 4.5 ) && (hr < 6 ))tim="-192"
if (( hr >= 6 ) && (hr < 7.5 ))tim="-256"
if (( hr >= 7.5 ) && (hr < 9 ))tim="-320"
if (( hr >= 9 ) && (hr < 10.5 ))tim="-384"
if (( hr >= 10.5 ) && (hr < 12 ))tim="-448"
if (( hr >= 12 ) && (hr < 13.5 ))tim="-512"
if (( hr >= 13.5 ) && (hr < 15 ))tim="-576"
if (( hr >= 15 ) && (hr < 16.5 ))tim="-640"
if (( hr >= 16.5 ) && (hr < 18 ))tim="-704"
if (( hr >= 18 ) && (hr < 19.5 ))tim="-768"
if (( hr >= 19.5 ) && (hr < 21 ))tim="-832"
if (( hr >= 21 ) && (hr < 22.5 ))tim="-896"
if (( hr >= 22.5 ) && (hr < 24 ))tim="-960"
document.write("<div class=\"tb\" style=\"background-position:center "+tim+"px;\"><\/div>");
</script>
这段js是根据用户时间输出相当于的值
如果用户不刷新页面 即便时间改变也不会更改相应的值
我就是想 用户不刷新页面 在时间改变时自动输出相应的值
参考答案:<HTML>
<HEAD>
<TITLE>test</TITLE>
<SCRIPT language=JavaScript>
function timeClock() {
day = new Date( )
hru = day.getHours( )
miu = day.getMinutes( )
mi = miu/60
hr = hru+mi
if (( hr >= 0 ) && (hr < 1.5 ))tim="0"
if (( hr >= 1.5 ) && (hr < 3 ))tim="-64"
if (( hr >= 3 ) && (hr < 4.5 ))tim="-128"
if (( hr >= 4.5 ) && (hr < 6 ))tim="-192"
if (( hr >= 6 ) && (hr < 7.5 ))tim="-256"
if (( hr >= 7.5 ) && (hr < 9 ))tim="-320"
if (( hr >= 9 ) && (hr < 10.5 ))tim="-384"
if (( hr >= 10.5 ) && (hr < 12 ))tim="-448"
if (( hr >= 12 ) && (hr < 13.5 ))tim="-512"
if (( hr >= 13.5 ) && (hr < 15 ))tim="-576"
if (( hr >= 15 ) && (hr < 16.5 ))tim="-640"
if (( hr >= 16.5 ) && (hr < 18 ))tim="-704"
if (( hr >= 18 ) && (hr < 19.5 ))tim="-768"
if (( hr >= 19.5 ) && (hr < 21 ))tim="-832"
if (( hr >= 21 ) && (hr < 22.5 ))tim="-896"
if (( hr >= 22.5 ) && (hr < 24 ))tim="-960"
document.clock.time.value = tim;
}
setInterval("timeClock()", 1000); // 循环定时调用
</SCRIPT>
</HEAD>
<BODY onLoad="timeClock();">
<FORM name=clock>
Time:<INPUT type=text name=time size=8 value=""> <BR>
</FORM>
</BODY>
</HTML>
大概吧,我写完还没去测试。。。用好setInterval就可以了