gpt4 book ai didi

javascript - 全日历自定义结束日期

转载 作者:行者123 更新时间:2023-11-29 15:31:09 25 4
gpt4 key购买 nike

是否可以根据选择框中的选择创建自定义结束日期?假设我有这个 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
.........

关于javascript - 全日历自定义结束日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34743236/

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