[英]fullcalendar remove event by popup modal strange behavior
我已經制作了全日歷事件刪除彈出模式。 這部分工作,但有奇怪的行為。 我是新手,所以我嘗試了幾種不同的方法,但我無法消除這種奇怪的行為。 而且我不知道如何讓 jsfiddle 在不復制我所有代碼的情況下重現確切的行為。 但我的代碼包含很多額外的東西。 所以我不能提供jsfiddle。 這里只說明相關代碼。 但我認為有人對此有很好的經驗。 我認為他們可以很容易地看穿代碼。 我非常感謝您的建議。 我在這上面花了太多時間。 奇怪的行為是通過彈出模式刪除事件,它刪除了之前通過關閉按鈕關閉的另一個事件。 在下面的解釋中包含詳細信息。
我做了這樣的:
1) 彈出模式的 div 代碼
<div class="modal fade" id="modalRemove" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<h4>Are you sure to remove the event?</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="close" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger" id="removeBtn" data-dismiss="modal">Remove</button>
</div>
</div>
</div>
</div>
2)當點擊事件時->彈出模式顯示->然后可以選擇(單擊)關閉按鈕或彈出模式上的刪除按鈕
eventRender: function (event, element){
element.click(function() {
$('#modalRemove').modal();
$('#eventTitle').html(event.title);
$("#removeBtn").click(function() {
$('#calendar').fullCalendar('removeEvents',event._id);
});
});
},
什么在起作用
什么是奇怪的行為
然后,我單擊 test1 的彈出窗口上的關閉按鈕(未刪除)-> 彈出窗口消失-> test1 事件仍按原樣顯示在全日歷上。 ====> 直到這里工作正常
然后,我單擊 test2 事件-> 彈出模式出現如圖 2 -> 按下 test2 的刪除按鈕 -> [問題] 然后兩個 test1、test2 事件都被刪除
為什么它會在 1、2、3、4 步后刪除這兩個事件?
嘗試這個:
eventRender: function(event, element) {
element.attr('href', 'javascript:void(0);');
element.click(function() {
//set the modal values and open
$('#eventTitle').html(event.title);
// Rebind the Remove button click handler
$("#removeBtn").off('click').on('click', function(e) {
$('#calendar').fullCalendar('removeEvents', event._id);
});
$('#modalRemove').modal();
});
}
請注意,在綁定特定事件之前,如何通過off()
將所有click
事件與#removeBtn
按鈕off()
綁定。
(在您的代碼中,每當您單擊日歷中的一個事件時, #removeBtn
將此事件的新click
處理程序綁定到#removeBtn
。因此,當您最終單擊“刪除”時,將執行多個處理程序。)
你可以這樣做
$(".popover").hide();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.