日历从右侧填充

时间:2013-10-14 16:52:42

标签: javascript loops calendar html-table

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

我已经添加了screenshot来显示我的电脑上的样子:

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;

        }
}

1 个答案:

答案 0 :(得分:0)

不知道我是如何错过这个但是你没有关闭添加空白日期的行的标记..

您只需使用

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

也不是+“”+