当我显示一个日历都可以正常工作时,我正在使用javascript制作日历,但是当我想在我的网页上显示两个日历时,似乎没有执行appendChild()函数之一
function showCalendar(month, year) {
let firstDay = (new Date(year, month)).getDay();
tbl = document.getElementById("calendar-body");
tb2 = document.getElementById("calendar-body2");// body of the calendar
// clearing all previous cells
tbl.innerHTML = "";
tb2.innerHTML = "";
// filing data about month and in the page via DOM.
monthAndYear.innerHTML = months[month] + " " + year;
monthAndYear2.innerHTML = months[month] + " " + year;
selectYear.value = year;
selectYear2.value = year;
selectMonth.value = month;
selectMonth2.value = month;
// creating all cells
let date = 1;
for (let i = 0; i < 6; i++) {
// creates a table row
let row = document.createElement("tr");
//creating individual cells, filing them up with data.
for (let j = 0; j < 7; j++) {
if (i === 0 && j < firstDay) {
cell = document.createElement("td");
cellText = document.createTextNode("");
cell.appendChild(cellText);
row.appendChild(cell);
}
else if (date > daysInMonth(month, year)) {
break;
}
else {
cell = document.createElement("td");
cellText = document.createTextNode(date);
if (((date === today.getDate())||(date === (today.getDate()-1))||(date === (today.getDate()-2))) && year === today.getFullYear() && month === today.getMonth()) {
cell.classList.add("bg-info");
} // color today's date
cell.appendChild(cellText);
row.appendChild(cell);
date++;
}
}
tbl.appendChild(row);
tb2.appendChild(row);
// appending each row into calendar body.
}
}
tbl.appendChild(row);
tb2.appendChild(row);
当我切换这两条指令时,第二条指令有效,但第一条指令无效