0

我正在制作日历,现在我应该让每个月都在正确的日子开始(否则他们都会从周日开始)。我已经制作了一个数组,其中包含我每个月需要的空数据单元的数量,然后才能开始计算天数。我设法让它用适量的空数据单元格填充日历,但是,空数据单元格从右侧开始填充第一行,而逻辑上它应该从左侧开始。

我已经包含了一个屏幕截图来显示它在我的 PC 上的样子:

http://imgur.com/y7r8B16

代码:

var months = new Array();
months[0] = "januari";
months[1] = "februari";
months[2] = "maart";
months[3] = "april";
months[4] = "mei";
months[5] = "juni";
months[6] = "juli";
months[7] = "augustus";
months[8] = "september";
months[9] = "oktober";
months[10] = "november";
months[11] = "december";

var maxDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var spaces = [2, 5, 5, 1, 3, 6, 1, 4, 0, 2, 5, 0];
var weekDays = ["zo", "ma", "di", "wo", "do", "vr", "za"];
var kalender = 0;
var days = 1;
var weekDaysNumber = 0;
var empty = 1;



while(kalender < months.length){
    document.write("<div id='table'><table><tr class='jaarrij'>");
    document.write("<th colspan='7'>" + months[kalender] + "</th></tr>");
    document.write("<tr class='weekrij'>");

    while(weekDaysNumber <= 6){
        document.write("<td>" + weekDays[weekDaysNumber] + "</td>");
        weekDaysNumber++
    }
    document.write("</tr>");
    document.write("<tr class='rij'>");

    var rows = 1;

    while(days < maxDays[kalender]){

        if(spaces[kalender] >= 1) {
            document.write("<td class='dag'>" + " " + "</td");

            rows++;
            spaces[kalender]--;

        }

        else if(spaces[kalender] < 1){
            document.write("<td class='dag'>" + days + "</td>");



            rows++;
            days++;
        }





        if(rows == 7 && days !== maxDays[kalender]){
        document.write("</tr>");
        document.write("<tr class='rij'>");
        rows = 0;
        }

    }

    if(days == maxDays[kalender]){
            document.write("</tr></table></div>");
            kalender++;
            weekDaysNumber=0;
            days= 1;

        }
}
4

1 回答 1

0

不知道我是怎么错过的,但是您还没有关闭添加空白日的行的标签..

你可以简单地使用

<td class='dag'></td>

太而不是 +" "+

于 2013-10-15T08:23:50.337 回答