该代码旨在使用 javascript 和表格生成日历。月份和日期是荷兰语,但应该可以理解。不知何故,这以无限循环结束,而当天数更大或与我的数组长度相同时它应该停止。
它应该每个月制作 12 个表,然后用当月的天数填满这些表。它还没有完成,因为它会假定每一天都将从星期日开始。我想我还应该注意,我还没有那么有经验。
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 weekDays = ["zo", "ma", "di", "wo", "do", "vr", "za"];
var kalender = 0;
var days = 1;
var weekDaysNumber = 0;
while(kalender < months.length){
document.write("<table><tr>");
document.write("<th>" + months[kalender] + "</th></tr>");
document.write("<tr>");
while (weekDaysNumber < 7){
document.write("<td>" + weekDays + "</td>";
weekDaysNumber++;
}
document.write("</tr>");
while(days < maxDays[kalender]){
document.write("<td>" + days + "</td>");
var rows = 0;
if(rows == 7 && days !== maxDays[kalender]){
document.write("</tr>");
document.write("<tr>");
rows = 1;
}
rows++;
days++;
}
if(days == maxDays[kalender]){
document.write("</tr></table>");
kalender++;
weekDaysNumber=0;
}
}