【发布时间】:2019-10-19 06:57:18
【问题描述】:
如何获得选择的时间?
在我的场景中,我有一个可选择的日历,用户可以选择日历的某些单元格,然后如果选择的时间小于 3 小时,它将继续执行一些操作,但如果时间差更大超过 3 小时,则会显示警告消息。
这是一个示例,但我想在
select事件之前进行。
https://codepen.io/nasser-ali-karimi/pen/KKKNzRB?editors=0010
$(function() {
$('#calendar').fullCalendar({
selectable: true,
defaultView: 'agendaDay',
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay'
},
select: function(startDate, endDate) {
// Find the time diff for checking the druation.
var fromTime = parseInt(new Date(startDate.format()).getTime()/1000);
var toTime = parseInt(new Date(endDate.format()).getTime()/1000);
var timeDiff = (toTime - fromTime)/3600; // will give difference in hrs
// Check if user selected time more than 3 hours then, show the warning.
if (timeDiff > 3) {
$('.fc-highlight').css('background', 'red');
}
else {
alert("continue !");
}
}
});
});
为了更好的用户体验,我想将所选部分的颜色更改为黄色或红色以警告用户。但我不知道有没有内置功能。
使用Fullcalendar v3 和moments.js!
【问题讨论】:
-
使用Fullcalendar v3和moments.js!
-
是的,但是应该是在选择过程中,所以当颜色变红时,用户会知道并可以减少它。
-
是的,它与 Drupal 8 集成,但我认为它在这里无济于事,因为我只是提到了一个警报操作。
-
我想你可以使用selectAllow 来做这个。我不认为它可以突出显示,但它确实会改变鼠标光标符号并在鼠标移动到无效区域时阻止选择。我现在不能轻松地进行演示(我只能使用移动设备),但我相当确定这会奏效。
-
文档说函数必须返回真或假。
标签: javascript jquery events callback fullcalendar