站长论坛

标题: 动态时钟的举例 [打印本页]

作者: superadmin    时间: 2007-10-5 21:11
标题: 动态时钟的举例
#######################JS代码#########################################
function Year_Month(){
    var now = new Date();
    var yy = now.getYear();
    var mm = now.getMonth()+1;
    var cl = '<font color="#000000">';
    if (now.getDay() == 0) cl = '<font color="#c00000">';
    if (now.getDay() == 6) cl = '<font color="#00c000">';
    return(cl +'<font color="#FF7311">'+yy+'</font>'+ '<font color="000000">年</font>'+'<font color="#FF7311">'+mm+'</font>'+'<font color="000000">月</font>');
}


function Date_of_Today(){
    var now = new Date();
    var cl = '<font color="#000000">';
    if (now.getDay() == 0) cl = '<font color="#c00000">';
    if (now.getDay() == 6) cl = '<font color="#00c000">';
    return(cl + '<font color="#FF7311">'+now.getDate()+'</font>'+ '<font color="000000">日</font>');
}

function Day_of_Today(){
    var day = new Array();
    day[0] = "<font color=000000>星期</font><font color=#FF7311>日</font>";
    day[1] = "<font color=000000>星期</font><font color=#FF7311>一</font>";
    day[2] = "<font color=000000>星期</font><font color=#FF7311>二</font>";
    day[3] = "<font color=000000>星期</font><font color=#FF7311>三</font>";
    day[4] = "<font color=000000>星期</font><font color=#FF7311>四</font>";
    day[5] = "<font color=000000>星期</font><font color=#FF7311>五</font>";
    day[6] = "<font color=000000>星期</font><font color=#FF7311>六</font>";
    var now = new Date();
    var cl = '<font color="#000000">';
    if (now.getDay() == 0) cl = '<font color="#c00000">';
    if (now.getDay() == 6) cl = '<font color="#00c000">';
    return(cl +  day[now.getDay()] + '</font>');
}

function CurentTime(){
    var now = new Date();
    var hh = now.getHours();
    var mm = now.getMinutes();
    var ss = now.getTime() % 60000;
    ss = (ss - (ss % 1000)) / 1000;
    var clock = hh+':';
    if (mm < 10) clock += '0';
    clock += mm+':';
    if (ss < 10) clock += '0';
    clock += ss;
    return(clock);
}

function refreshCalendarClock(){
document.all.calendarClock1.innerHTML = Year_Month();
document.all.calendarClock2.innerHTML = Date_of_Today();
document.all.calendarClock3.innerHTML = Day_of_Today();
document.all.calendarClock4.innerHTML = CurentTime();
}

setInterval('refreshCalendarClock()',1000);

#######################以下是HTML代码引用上面的JS代码###########################

<tr bgcolor=#FEFEEF><td align="center" width="100%" height="100%">
<font id="calendarClock1" style="font-family:宋体;font-size:15px;color:red;"></font>
<!--<font id="calendarClock1" style="font-family:Arial;font-size:15px;color:red;font-weight:bold"></font>-->
<font id="calendarClock2" style="font-family:宋体;font-size:15px;color:red;"> </font><br>
<font id="calendarClock3" style="font-family:宋体;font-size:13px;"> </font><br>
<font id="calendarClock4" style="color:#100080;font-family:Arial;font-size:12px;"></font>
</td></tr>




欢迎光临 站长论坛 (https://www.tzlink.com/bbs/) Powered by Discuz! X3.2