要实现万年历的宜忌功能,需要先准备好宜忌数据。这里提供一个简单的实现:
```javascript
const yijiData = {
"1": { "1": "祭祀,搬家,结婚,入宅,开市,订婚,纳采,裁衣", "2": "进人口,安葬" },
"2": { "1": "祭祀,开光,求嗣,解除,伐木,拆卸,修造,栽种,纳畜,安葬", "2": "嫁娶,进人口,移徙,出火,入宅,开市,立券,赴任" },
"3": { "1": "祭祀,求医,治病,开仓,出货财,安葬", "2": "嫁娶,出行,动土,开市,修造,上梁,入宅,移徙,栽种" },
// ... 其他月份的数据
};
const jiriData = {
"1": "日值神煞:天赦 喜神 阴德 官日",
"2": "日值神煞:月德合 天恩 月恩 玉堂",
"3": "日值神煞:月德合 天恩 月恩 玉堂",
// ... 其他日期的数据
};
```
然后,在 `getCalendar()` 函数中,可以添加宜忌数据的处理:
```javascript
function getCalendar(year, month) {
const daysInMonth = getDaysInMonth(year, month);
const firstDayOfWeek = getDayOfWeek(year, month, 1);
const calendar = [];
let week = [null, null, null, null, null, null, null];
for (let day = 1, i = 0; day <= daysInMonth; day++, i++) {
const jiri = jiriData[day]; // 获取日值信息
const yiji = yijiData[month][day]; // 获取宜数据
const jiji = yijiData[month][day + 15]; // 获取忌数据
week[i] = { day, jiri, yiji, jiji }; // 把数据添加到每个日期对象中
if (getDayOfWeek(year, month, day) === "六" || day === daysInMonth) {
calendar.push(week);
week = [null, null, null, null, null, null, null];
i = -1;
}
}
return { calendar, firstDayOfWeek };
}
```
最后,在 `createCalendarTable()` 函数中,将宜忌数据添加到表格中:
```javascript
function createCalendarTable(year, month) {
const { calendar, firstDayOfWeek } = getCalendar(year, month);
let table = "<table>";
table += "<tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>";
for (let week of calendar) {
table += "<tr>";
for (let day of week) {
if (day === null) {
table += "<td></td>";
} else {
table += `
<td>
<div class="day">${day.day}</div>
<div class="jiri">${day.jiri}</div>
<div class="yiji">${day.yiji}</div>
<div class="jiji">${day.jiji}</div>
</td>
`;
}
}
table += "</tr>";
}
table += "</table>";
return table;
}
```
这样就可以在表格中显示每个日期对应的宜忌了。