我在我的项目中使用 fomantic 日历。日历显示正确。当月份更改时,我想做一些操作。在 fomantic 日历中是否有任何月份更改事件。发现很难使其工作。我在这里先向您的帮助表示感谢。
<div class="ui calendar" id="calendar">
</div>
我已经像这样初始化日历 ngOnInit() { $('#calendar').calendar({ type: 'date' }); }
当我点击如图所示的箭头图标时,我想做一些动作
我在我的项目中使用 fomantic 日历。日历显示正确。当月份更改时,我想做一些操作。在 fomantic 日历中是否有任何月份更改事件。发现很难使其工作。我在这里先向您的帮助表示感谢。
<div class="ui calendar" id="calendar">
</div>
我已经像这样初始化日历 ngOnInit() { $('#calendar').calendar({ type: 'date' }); }
当我点击如图所示的箭头图标时,我想做一些动作
Fomantic-UI 日历模块有一个事件onBeforeChange
,您可以使用它来确定年份变化
$('.ui.calendar').calendar({
type: 'date',
onBeforeChange: function(newDate){
var oldDate = $(this).calendar('get date');
if(!oldDate || oldDate.getFullYear() != newDate.getFullYear()) {
console.log('Year has changed!');
}
}
});
初始化后,如果你查看 Javascript 生成的代码,你可以看到左箭头在 div 中class="prev"
,右箭头在 div 中class="next"
。
所以你可以做这样的事情
$('#calendar prev, #calendar next').click(function() {
//do something
})