更改JavaScript日历日期

时间:2013-02-16 21:54:59

标签: javascript html

我为自己的网站创建了一个Javascript / HTML日历。 (下面的HTML)。

<table width="690" cellpadding="0" cellspacing="0" border="2" bordercolor="#999999">
<tr class="week">
    <td width="98" class="dayofweek">Sunday</td>
    <td width="98" class="dayofweek">Monday</td>
    <td width="98" class="dayofweek">Tuesday</td>
    <td width="98" class="dayofweek">Wednesday</td>
    <td width="98" class="dayofweek">Thursday</td>
    <td width="98" class="dayofweek">Friday</td>
    <td width="98" class="dayofweek">Saturday</td>
</tr>
<tr class="week" valign="top">
    <td class="day" id="d1"><div class="daynumb" id="1"></div></td>
    <td class="day" id="d2"><div class="daynumb" id="2"></div></td>
    <td class="day" id="d3"><div class="daynumb" id="3"></div></td>
    <td class="day" id="d4"><div class="daynumb" id="4"></div></td>
    <td class="day" id="d5"><div class="daynumb" id="5"></div></td>
    <td class="day" id="d6"><div class="daynumb" id="6"></div></td>
    <td class="day" id="d7"><div class="daynumb" id="7"></div></td>
</tr>
<tr class="week" valign="top">
    <td class="day" id="d8"><div class="daynumb" id="8"></div></td>
    <td class="day" id="d9"><div class="daynumb" id="9"></div></td>
    <td class="day" id="d10"><div class="daynumb" id="10"></div></td>
    <td class="day" id="d11"><div class="daynumb" id="11"></div></td>
    <td class="day" id="d12"><div class="daynumb" id="12"></div></td>
    <td class="day" id="d13"><div class="daynumb" id="13"></div></td>
    <td class="day" id="d14"><div class="daynumb" id="14"></div></td>
</tr>
<tr class="week" valign="top">
    <td class="day" id="d15"><div class="daynumb" id="15"></div></td>
    <td class="day" id="d16"><div class="daynumb" id="16"></div></td>
    <td class="day" id="d17"><div class="daynumb" id="17"></div></td>
    <td class="day" id="d18"><div class="daynumb" id="18"></div></td>
    <td class="day" id="d19"><div class="daynumb" id="19"></div></td>
    <td class="day" id="d20"><div class="daynumb" id="20"></div></td>
    <td class="day" id="d21"><div class="daynumb" id="21"></div></td>
</tr>
<tr class="week" valign="top">
    <td class="day" id="d22"><div class="daynumb" id="22"></div></td>
    <td class="day" id="d23"><div class="daynumb" id="23"></div></td>
    <td class="day" id="d24"><div class="daynumb" id="24"></div></td>
    <td class="day" id="d25"><div class="daynumb" id="25"></div></td>
    <td class="day" id="d26"><div class="daynumb" id="26"></div></td>
    <td class="day" id="d27"><div class="daynumb" id="27"></div></td>
    <td class="day" id="d28"><div class="daynumb" id="28"></div></td>
</tr>
<tr class="week" valign="top">
    <td class="day" id="d29"><div class="daynumb" id="29"></div></td>
    <td class="day" id="d30"><div class="daynumb" id="30"></div></td>
    <td class="day" id="d31"><div class="daynumb" id="31"></div></td>
    <td class="day" id="d32"><div class="daynumb" id="32"></div></td>
    <td class="day" id="d33"><div class="daynumb" id="33"></div></td>
    <td class="day" id="d34"><div class="daynumb" id="34"></div></td>
    <td class="day" id="d35"><div class="daynumb" id="35"></div></td>
</tr>

我创建了一个JavaScript函数,用于检查加载日期,并调用正确的函数来相应地更改月份。换句话说,日历日期将始终在变化。我需要创建一个JS函数来改变每个月的日期。下面是我正在使用的JavaScript。它什么都不做。我已经在评论中向你(以及我自己)展示了发生了什么。

function february() { //this is the function for February
var numbdays = 28; //February has 28 days

for (var date=1 /* February starts on Day 1 */;date<=numbdays /* make sure it doesn't exceed 28 days */;date++ /* advance the date number */) { 
    for (var id=6 /* Day 1 of Feb is on the id "6" */;id<=34 /* 6+28=34, don't exceed past id "34" */;id++ /* advance the id number */) {
        var idstring = id.toString(); //I have no clue if the toStrings even need to be here.
        var datestring = date.toString();
        document.getElementById(idstring).innerHTML = datestring; //change the text to the correct date for the correct id.
    }
}

} //什么都没发生......

有什么想法吗?我做错了什么?

0 个答案:

没有答案