在jquery函数内部打开模态保存更改并继续返回jquery函数



我是jQuery和bootstrap的新手。我有一个jQuery函数,它是由另一个点击事件触发的,然后我打开模态,模态有几个输入字段,保存后,我想继续返回启动show模态的jQuery函数。

此外,当我保存模态中的数据时,它会调用另一个函数来保存值。是否有类似"等待模态关闭"的内容。

代码段(共享伪代码(

select: function(start, end, allDay) {
//opening the modal here...
$('#myModal').modal('show');

if (title) {
console.log(title)
calendar.fullCalendar('renderEvent', {
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
}

//modal code , closing it once data is fetched..
$('#testData').submit(function (event) {
event.preventDefault();
startTime= $('#startTime').val();
endTime=$('#endTime').val();
title=$('titleH').val();
console.log(startTime);
console.log(endTime);
$('#myModal').modal('close');
});

关闭模态后,如何返回到上一个函数回调?

在显示模态之后,您不能真正返回到显示模态的函数。您可以做的是将事件处理程序绑定到模态的关闭事件,该事件调用包含要在模态关闭后执行的逻辑的函数。如果我正确理解了您的代码,我认为您希望在模态关闭后执行以下逻辑:

if (title) {
console.log(title)
calendar.fullCalendar('renderEvent', {
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');

这是正确的吗?如果是这样的话,像这样的东西应该会起作用:

$('#myModal').on('hidden.bs.modal', function () {
if (title) {
console.log(title)
calendar.fullCalendar('renderEvent', {
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
});

最新更新