shown.bs.modal fires multiple times when you close and reopen modal

后端 未结 7 521
囚心锁ツ
囚心锁ツ 2020-12-29 08:07

I have made a fiddle illustrating the issue I am facing at the moment. So every time I close and open a modal, shown.bs.modal also fires multiple times. In this

7条回答
  •  一向
    一向 (楼主)
    2020-12-29 08:34

    The function below is used for all the dialogs in my application.

    It gets called each time with a different callback to execute. The easiest solution for me is simply to remove the event handler before adding a new one.

    function messageBox(action,...) {               
        $("#modal-btn-ok").off("click");
        $("#modal-btn-ok").on("click", function(e) {
            action(e);
        }); 
    

提交回复
热议问题