是否可以根据选择框中的选择创建自定义结束日期?假设我有这个HTML-它有一个标题和一个事件的持续时间:
<select name="event-title" id="event-title">
<option value="Træning" data-duration="01:00">Træning</option>
<option value="Træning + Måling" data-duration="01:15">Træning og måling</option>
<option value="Billeder" data-duration="00:20">Foto Session</option>
</select>
单击添加事件时,结束日期/时间应为单击的日期和开始时间+持续时间:
请参阅此处的代码和注释:
select: function (start, end, allDay) {
$('#fc_create').click(); //trigger modal
var startHours = moment(start).format('hh:mm'),
started = start,
ended = end;
//started variable could return: Mon Jan 11 2016 09:10:00 GMT+0000
//Set value to selected time
$("#event-start").val(startHours);
$(".antosubmit").on("click", function () {
var title = $("#event-title").val(),
duration = $("#event-title").find("option:selected").data('duration');
if (end) {
//Returns ex: Mon Jan 11 2016 09:35:00 GMT+0000
// However, the end time here should be the starttime + the duration - So in this it should be: 10.10
// as the start time was 09:10 + a duration on 1 hour (from the selectbox)
ended = end
}
if (title) {
calendar.fullCalendar('renderEvent', {
title: title,
start: started,
end: end,
allDay: false
},
true); // make the event "stick"
}
$('#title').val('');
calendar.fullCalendar('unselect');
$('.antoclose').click();
return false;
});
}
试试这个!
var title = $("#event-title").val(),
duration = $("#event-title").find("option:selected").data('duration');
var newDurationDate = moment(start.format('YYYY-MM-DD')+' '+duration+':00');
var durationInMinutes = (newDurationDate.hour()*60)+newDurationDate.minute());
//Overwrite value of end
end = moment(start).add(durationInMinutes, 'minutes');
console.log(endDate.format('YYYY-MM-DD HH:mm'));
if (end) {
//Returns ex: Mon Jan 11 2016 09:35:00 GMT+0000
.........