gpt4 book ai didi

javascript - 如何在 FullCalendar 中更改所选日期的背景颜色

转载 作者:太空狗 更新时间:2023-10-29 12:30:00 39 4
gpt4 key购买 nike

我正在尝试更改日历中所选日期的背景颜色。在我下面的代码中,它突出显示了所有点击的日期,我怎样才能只突出显示最后点击的日期?

dayClick: function (day){
var mydate = new Date(this[0].getAttribute("data-date"));
var dateArray = mydate.toDateString().split(" ");
document.querySelectorAll(".calendar-mobile p")[0].innerHTML = j_monthNames[mydate.getMonth()] + " " + mydate.getDate() + "日" + "(" + j_dayNames[dateArray[0].toLocaleLowerCase()] + ")";
document.body.classList.remove("calendar-open");

$month = '' + (mydate.getMonth() + 1);
$day = '' + mydate.getDate();
$year = mydate.getFullYear();

if ($month.length < 2) $month = '0' + $month;
if ($day.length < 2) $day = '0' + $day;
$dates = [$year, $month, $day].join('-');
$('[data-date='+$dates+']').css({"color": "red", "backgroundColor": "yellow",});
},

最佳答案

我终于这样解决了:

$(document).ready(function() {
$('#calendars').fullCalendar({
header: {
left: 'prev',
center: 'title',
right: 'next'
},
selectable: true,
});
});
.fc-highlight {
background: green !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.min.css" defer/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.0.1/fullcalendar.min.js" defer></script>
<div id="calendars"></div>

只需触发 .fc-highlight 类即可。

关于javascript - 如何在 FullCalendar 中更改所选日期的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55323256/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com