0

我想防止在单击按钮且未选中任何复选框时显示 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 我无效

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

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

4

2 回答 2

2

感谢您的回复。我最终使用了 $.magnificPopup.close(); 但是,重要的是,我把我的代码放在了 magnific popup 的初始化之后。以前,我在初始化之前就有了。愚蠢的错误!所以我的工作 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
    }
}); 

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

于 2019-05-20T08:33:00.427 回答
1

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

于 2019-05-17T16:02:45.710 回答