Stop/destroy jQuery 中的 Magnific Popup

Stop/destroy Magnific Popup in jQuery

我想阻止在单击按钮和未选中复选框时显示 magnificPopup 对话框。

这是我已经尝试过的方法:

$('[id$=DeleteSelectedItems]').click(function (evt) {
  if ($("#datatable :checked").length == 0) {
    evt.preventDefault();
    $.magnificPopup.remove(); //prevent dialog popup if no checkbox selected
  }
});

除了 $.magnificPopup.remove(); 上面的代码是我想要的。不是有效函数。

所以尽管 $.magnificPopup.remove();防止弹出窗口显示,(因为它破坏了 JavaScript!)它不是一个有效的函数,我在测试它时在我的控制台中收到错误。我试过 $.magnificPopup.destroy();和 $.magnificPopup.stop();但它们也无效。

非常感谢您为此提供的任何帮助!

也许 evt.preventDefault(); 足以停止弹出窗口显示,您可以删除代码行 $.magnificPopup.remove();以这种方式避免控制台中的错误。

感谢您的回复。我最终使用了 $.magnificPopup.close();但是,重要的是,我将我的代码 放在 初始化 magnific 弹出窗口之后。以前,我在初始化之前就拥有它。愚蠢的错误!所以我的工作 jQuery 是:

// initialise magnific popup
$('.open-popup-link').magnificPopup({
   type: 'inline',
   midClick: true
});

//don't fire the delete button if no checkbox selected in table with id of datatable
$('[id$=DeleteSelectedItems]').click(function (evt) {
   if ($("#datatable :checked").length == 0) {
       evt.preventDefault();
       $.magnificPopup.close(); //prevent dialog popup if no checkbox selected
    }
}); 

非常感谢您为我指明了正确的方向! :)