Javascript 当调用内联ajax时,放大弹出窗口仅在第二次单击时工作

Javascript 当调用内联ajax时,放大弹出窗口仅在第二次单击时工作,javascript,jquery,magnific-popup,Javascript,Jquery,Magnific Popup,我试图调用一个本地网页来加载到放大弹出覆盖中,但它只在第二次单击时这样做 在我的“网络”选项卡中,我可以看到它正在请求该页面,但在第二次单击之前,它不会启动覆盖并加载该html 我是JS的大三学生,所以我真的不确定我需要做什么,所以任何指点都会被欣赏 Component.prototype = { init: function () { var that = this; this.$element.on('click tap',function(e){

我试图调用一个本地网页来加载到放大弹出覆盖中,但它只在第二次单击时这样做

在我的“网络”选项卡中,我可以看到它正在请求该页面,但在第二次单击之前,它不会启动覆盖并加载该html

我是JS的大三学生,所以我真的不确定我需要做什么,所以任何指点都会被欣赏

Component.prototype = {

    init: function () {
        var that = this;

        this.$element.on('click tap',function(e){
            e.preventDefault();
            that._galleryId = that.$element.attr('href'); //get the url from the link we've just clicked
            that._initialiseGallery(that);

        });

    },
    _onGalleryOpen: function(that){
        console.log('test5');
        if(that.options.fullScreenType === 'image'){
            $(window).trigger('resize');
        }
    },

    _initialiseGallery: function(that) {

        that.$element.magnificPopup({
          items: {
            src: that._galleryId
          },
          type: 'ajax',

            callbacks: {
                open: function() {
                    that._onGalleryOpen(that);
                },
                close: function() {
                  // Will fire when popup is closed
                },
              parseAjax: function(mfpResponse) {
                // mfpResponse.data is a "data" object from ajax "success" callback
                // for simple HTML file, it will be just String
                // You may modify it to change contents of the popup
                // For example, to show just #some-element:
                mfpResponse.data = $(mfpResponse.data).find('.Gallery');

              },
              ajaxContentAdded: function() {
                // Ajax content is loaded and appended to DOM
              }
            }
        });
    }
}
如此变化:

that.$element.magnificPopup({
致:

成功了

我在这里找到了解决方案:

$.magnificPopup.open({...});