7

我正在使用Magnific Popup上传图片。当用户单击或按下关闭按钮时,我想得到用户的确认是否关闭。

这是我的 Javascript:

$('#upload').magnificPopup({
    type:'inline',
    callbacks: {
        close: function(){
            if( confirm("Are you sure you want to close?") ) {
              return true;
            }
              return false;
            }
          }
      }
});

但它不起作用。

4

2 回答 2

11

您可以覆盖 close 方法。通过修改instance,您只会更改此特定弹出窗口的功能。然后只需调用原始close方法即可完成工作。

$('#upload').magnificPopup({
  type:'inline',
  callbacks: {
    open: function() {
      $.magnificPopup.instance.close = function() {
        // Do whatever else you need to do here
        var confirmed = confirm("Are you sure you want to close?");
        if(!confirmed) {
          return;
        }

        // Call the original close method to close the popup
        $.magnificPopup.proto.close.call(this);
      };
    }
  }
});
于 2014-06-27T17:57:44.130 回答
3

You could try:

( '#upload' ).magnificPopup({
    type: 'inline',
    callbacks: {
      close: function(){
         var didConfirm = confirm( "Are you sure?" );
         if( didConfirm == false ){
            return false;
         }
      }
    }
});
于 2013-06-14T05:38:06.517 回答