thd*_*thd 4 jquery fullcalendar
当上个月少于当前月份时,如何禁用prev按钮?
例如,如果当前月份是8月,那么我想禁用上一个月份按钮,以便看不到7月。
小智 5
该代码检查fc-state-disabled或ui-state-disabled,因此不需要释放按钮。
viewRender: function( view, element ) {
// Drop the second param ('day') if you want to be more specific
if(moment().isAfter(view.intervalStart, 'day')) {
$('.fc-prev-button').addClass('fc-state-disabled');
} else {
$('.fc-prev-button').removeClass('fc-state-disabled');
}
}
Run Code Online (Sandbox Code Playgroud)
您可以自己轻松完成此操作,这是一个有效的示例。
我通过更改 fullcalendar.js 来完成此操作。请注意,在许多示例中,您可以使用上一个/下一个按钮更改年、月和日。其中每个都有自己的渲染函数,因此如果您想要每个函数都使用它,则需要考虑这一点。我的例子可以很容易地进行修改。
在我的示例中,当“禁用”时,我还将上一个按钮设置为红色。您可以自行决定如何处理此问题。
views.month = function(element, options, viewName) {
return new Grid(element, options, {
render: function(date, delta) {
if (delta == -1) {
var curr_date = new Date();
var curr_m = curr_date.getMonth();
if (date.getMonth() < curr_m) {
return false;
} else if ((date.getMonth() - 1) < curr_m) {
$(".fc-button-prev span").css("background", "red");
} else {
$(".fc-button-prev span").css("background", "#E8E8E8");
}
} else {
$(".fc-button-prev span").css("background", "#E8E8E8");
}
Run Code Online (Sandbox Code Playgroud)
这从 fullcalendar.js 中的第 :944 行开始
我已使用下载 FullCalendar 时提供的 basic-view.html 和 default.html 示例在 Firefox 3.6.8 中对此进行了测试。只需更改:
<script type='text/javascript' src='../fullcalendar.min.js'></script>
Run Code Online (Sandbox Code Playgroud)
到
<script type='text/javascript' src='../fullcalendar.js'></script>
Run Code Online (Sandbox Code Playgroud)