以下のJavascritのコードが、Kintone Portal Designerを使うと動作しません。
本日の日付を取得し、表示する処理になります。
HTML側にはid=todayの要素があります。
ローカルブラウザでは問題なく動きました。
ご助言をいただけると幸いです。
document.addEventListener("DOMContentLoaded", function () {
const sixYao = ["大安", "赤口", "先勝", "友引", "先負", "仏滅"];
const holidays = {
"2025-01-01": "元日",
"2025-01-13": "成人の日",
"2025-02-11": "建国記念の日",
"2025-02-24": "休日",
"2025-02-23": "天皇誕生日",
"2025-03-20": "春分の日",
"2025-04-29": "昭和の日",
"2025-05-03": "憲法記念日",
"2025-05-04": "みどりの日",
"2025-05-05": "こどもの日",
"2025-05-06": "休日",
"2025-07-15": "海の日",
"2025-08-11": "山の日",
"2025-08-12": "休日",
"2025-09-15": "敬老の日",
"2025-09-23": "秋分の日",
"2025-10-13": "スポーツの日",
"2025-11-03": "文化の日",
"2025-11-23": "勤労感謝の日",
"2025-12-30": "年末年始休暇",
"2025-12-31": "年末年始休暇"
};
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const date = today.getDate();
const dayIndex = today.getDay();
const daysOfWeek = ["日", "月", "火", "水", "木", "金", "土"];
const formattedDate = `${year}-${String(month).padStart(2, "0")}-${String(date).padStart(2, "0")}`;
const sixYaoIndex = (year + month + date) % 6;
let displayText = `今日は ${year}年${month}月${date}日(${daysOfWeek[dayIndex]}) ${sixYao[sixYaoIndex]} です`;
if (holidays[formattedDate]) {
displayText += ` (${holidays[formattedDate]})`;
}
console.log("表示する日付テキスト:", displayText);
const todayElement = document.getElementById("today");
if (todayElement) {
todayElement.textContent = displayText;
console.log("日付を表示しました");
} else {
console.error("ID 'todayis' の要素が見つかりません");
}
});