0
這是我handler
:爲DIV Click處理程序不jQuery的完整的日曆工作
$("div.fc-content").on('click', function (e) {
var id = $(this).data('id');
$.ajax({
url: '/VacationRequest/Edit/' + id,
cache: false
}).done(function (data) {
$("#edit-id").val(data.Id);
$("#startDate-edit").val(data.startDate);
$("#endDate-edit").val(data.endDate);
$("#comment-edit").val(data.comment);
$("#vacationTypes-edit").val(data.vacationType);
$('#edit-vacation-modal-window').modal('show');
});
});
這是Jquery
完整的日曆初始化的一部分:
function InitCalendar() {
$('#calendar').fullCalendar({
events: {
url: '/vacation/SchedulesGet',
type: 'POST',
data: {
title: 'title',
id : 'id',
start: new Date('start'),
end: new Date('end'),
},
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow',
textColor: 'black'
},
eventRender: function (event, element) {
$($(element[0]).find('div.fc-content')[0]).attr('data-id', event.id);
},
這$("div.fc-content")
塊是存在(我在js控制檯中找到它)。但是當我試圖點擊它時,什麼都沒發生。你能解釋我做錯了什麼嗎?
非常感謝!是工作!但你能解釋我嗎?爲什麼?我不明白( – Alexander
更新了答案。基本上使用一個委託事件處理程序允許你處理*在你實際綁定處理程序後創建的DOM元素的事件 – dekkard
好吧,據我所知,有必要把處理程序這是一個問題,對嗎? – Alexander