我有类似的this完整日历,如您所见,您可以创建事件并将其写入输入并单击按钮。
而不是我有一个选择,我想在其中创建具有选定值的事件,有可能吗?
HTML:
<select id="lstRegion" class="form-control select2 select2-accessible agenda_space" aria-hidden="true"></select>
<a href="javascript:;" id="event_add" class="btn green"> Add Event </a> </div>
<div id="event_box" class="margin-bottom-10"></div>
JS:
//load region dropdown
$("#lstRegion")
.getJSONCatalog({
onSuccess: function (response) {
console.log(response);
},
url: '/Agenda/GetRegion',
valueProperty: "ID",
textProperty: "valor"
});
//Event logic
var initDrag = function (el) {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim(el.text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
el.data('eventObject', eventObject);
// make the event draggable using jQuery UI
el.draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
};
var addEvent = function (title) {
title = title.length === 0 ? "Untitled Event" : title;
var html = $('<div class="external-event label label-default">' + title + '</div>');
jQuery('#event_box').append(html);
initDrag(html);
};
$('#external-events div.external-event').each(function () {
initDrag($(this));
});
$('#event_add').unbind('click').click(function () {
var title = $('#event_title').val();
addEvent(title);
});
最佳答案
如果您有如下代码:
<select id="lstRegion" class="form-control select2 select2-accessible agenda_space" aria-hidden="true">
<option>Appointment</option>
<option>All Day Event</option>
<option>Meeting</option>
</select>
您将想要使用:
$('#event_add').unbind('click').click(function () {
var title = $('#lstRegion option:selected').html();
addEvent(title);
});
这将从<select>
中选择当前选定的选项。然后阅读innerHTML
<option>
的.
关于javascript - 获取选定的值以添加事件 fullCalendar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44317646/