html日历页面节假日_基于jquery实现可查询节假日万年历代码

特效描述:基于jquery实现 可查询节假日 万年历代码。基于jquery实现可查询节假日万年历代码代码结构1. 引入CSS2. 引入JS3. HTML代码style="cursor:hand;color: white; border-bottom: 1px solid white;"onclick="dateSelection.show()">class="topDateFont">...
摘要由CSDN通过智能技术生成

特效描述:基于jquery实现 可查询节假日 万年历代码。基于jquery实现可查询节假日万年历代码

代码结构

1. 引入CSS

2. 引入JS

3. HTML代码

style="cursor:hand;color: white; border-bottom: 1px solid white;"

οnclick="dateSelection.show()">

class="topDateFont">年

class="topDateFont">

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的HTML+CSS+JS实现日历,包含节假日的显示: HTML代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>日历</title> <link rel="stylesheet" type="text/css" href="calendar.css"> </head> <body> <div class="calendar"> <div class="header"> <span class="prev" onclick="prevMonth()"><</span> <span class="date" id="date"></span> <span class="next" onclick="nextMonth()">></span> </div> <table> <thead> <tr> <th>日</th> <th>一</th> <th>二</th> <th>三</th> <th>四</th> <th>五</th> <th>六</th> </tr> </thead> <tbody id="tbody"> </tbody> </table> </div> <script src="calendar.js"></script> </body> </html> ``` CSS代码: ```css .calendar { width: 300px; margin: 20px auto; border: 1px solid #ccc; box-shadow: 0 0 5px #ccc; font-size: 14px; font-family: Arial, sans-serif; } .header { background-color: #f0f0f0; text-align: center; padding: 10px; position: relative; } .header span { cursor: pointer; } .prev { position: absolute; left: 10px; top: 10px; } .next { position: absolute; right: 10px; top: 10px; } .date { font-weight: bold; } table { width: 100%; border-collapse: collapse; } thead th { background-color: #f0f0f0; border: 1px solid #ccc; padding: 5px; text-align: center; } tbody td { border: 1px solid #ccc; padding: 5px; text-align: center; } .today { background-color: #c0c0c0; } .holiday { color: red; } ``` JS代码: ```js var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var tbody = document.getElementById("tbody"); var dateEle = document.getElementById("date"); // 获取当前月份的天数 function getDaysInMonth(year, month) { return new Date(year, month, 0).getDate(); } // 获取当前月份第一天是星期几 function getFirstDayOfWeek(year, month) { return new Date(year, month - 1, 1).getDay(); } // 获取当前月份的所有日期 function getDates(year, month) { var daysInMonth = getDaysInMonth(year, month); var firstDayOfWeek = getFirstDayOfWeek(year, month); var dates = []; for (var i = 1; i <= daysInMonth; i++) { dates.push(i); } for (var i = 0; i < firstDayOfWeek; i++) { dates.unshift(""); } return dates; } // 获取指定日期的节假日 function getHoliday(year, month, day) { var holidays = { "0101": "元旦", "0214": "情人节", "0308": "妇女节", "0312": "植树节", "0401": "愚人节", "0501": "劳动节", "0601": "儿童节", "0701": "建党节", "0801": "建军节", "0910": "教师节", "1001": "国庆节", "1224": "平安夜", "1225": "圣诞节" }; var monthStr = (month < 10 ? "0" : "") + month; var dayStr = (day < 10 ? "0" : "") + day; var dateStr = monthStr + dayStr; if (holidays[dateStr]) { return holidays[dateStr]; } return ""; } // 显示指定年月的日历 function showCalendar(year, month) { var dates = getDates(year, month); var html = ""; for (var i = 0; i < dates.length; i++) { if (i % 7 === 0) { html += "<tr>"; } var date = dates[i]; var holiday = getHoliday(year, month, date); if (holiday !== "") { html += '<td class="holiday">' + date + '<br>' + holiday + '</td>'; } else if (date !== "") { if (year === new Date().getFullYear() && month === new Date().getMonth() + 1 && date === new Date().getDate()) { html += '<td class="today">' + date + '</td>'; } else { html += "<td>" + date + "</td>"; } } else { html += "<td></td>"; } if (i % 7 === 6) { html += "</tr>"; } } tbody.innerHTML = html; dateEle.innerHTML = year + "年" + month + "月"; } // 上一个月 function prevMonth() { month--; if (month < 1) { month = 12; year--; } showCalendar(year, month); } // 下一个月 function nextMonth() { month++; if (month > 12) { month = 1; year++; } showCalendar(year, month); } // 显示当前月份的日历 showCalendar(year, month); ``` 这个日历会显示当前月份的日期,并标出当天和节假日。你可以根据自己的需要修改CSS样式和节假日数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值