我是 jQuery 和 bootstrap 的新手。 我有一个由另一个单击事件触发的 jQuery 函数,然后我打开模态,模态有几个输入字段,一旦保存它们,我想继续返回到启动显示模态的 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');
});
模态关闭后,如何返回到上一个函数回调?
最佳答案
在显示模态后,您无法真正返回到显示模态的函数。您可以做的是将事件处理程序绑定(bind)到模式的关闭事件,该事件调用包含您想要在模式关闭后执行的逻辑的函数。如果我正确理解您的代码,我认为您希望在模式关闭后执行以下逻辑:
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');
});
关于javascript - 在 jquery 函数中打开模态保存更改并继续返回 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58525838/