【问题标题】:Open popup from another function - Magnific Popup从另一个功能打开弹出窗口 - Magnific Popup
【发布时间】:2014-02-21 07:37:20
【问题描述】:

我想在调用 ajaxCall 函数时打开弹出窗口。

像这样:

function ajaxCall()
{

 openPopup();

}

function openPopup()
{

$('.popup-modal').magnificPopup({

type: 'inline',
modal: false,

});

$(document).on('click', '.closePopup', function (e) 
            {
                e.preventDefault();
                $.magnificPopup.close();
            });

}

这是小提琴: http://jsfiddle.net/qweWa/33/

我希望在调用 ajaxCall 函数时打开此弹出窗口。

这是 onclick 按钮打开弹出窗口的工作小提琴:

http://jsfiddle.net/qweWa/27/

【问题讨论】:

  • $.magnificPopup 不是函数 --> 错误!请纠正
  • 请立即查看我的帖子。我添加了一个适用于 onclick 按钮的工作小提琴
  • 还有你的 ajax 函数?
  • 这里不需要ajax函数。我只想在调用 ajaxCall 函数时打开这个弹出窗口。

标签: javascript jquery popup magnific-popup


【解决方案1】:

使用 open() 函数

function openPopup(el) { // get the class name in arguments here
            $.magnificPopup.open({
                items: {
                    src: '#thanksModal',
                },
                type: 'inline'
            });
}

JSFiddle : http://jsfiddle.net/t5f5e5zw/2/

【讨论】:

    【解决方案2】:

    你必须在函数中传递被点击按钮的类名:

    function openPopup(el) { // get the class name in arguments here
       $('.'+el).magnificPopup({ // use it here
          type: 'inline',
          modal: false
       });
    }
    
    $(function () {
       $('.ajax-call').click(function (e) {
          openPopup(this.className); //<----pass the clicked button's class name
       });
       $(document).on('click', '.closePopup', function (e) {
          e.preventDefault();
          $.magnificPopup.close();
       });
    });
    

    Demo Fiddle

    【讨论】:

      【解决方案3】:

      magnificPopup is not a function 错误。 请在您的标题部分中包含任何自定义 js 文件。

      【讨论】:

      • 请立即查看我的帖子。我添加了一个适用于 onclick 按钮的工作小提琴
      • 是的,它现在可以工作了,但是你在调用 ajaxCall() 时遇到了什么错误?
      • 我不想在按钮单击时绑定它。我希望在调用 ajaxCall() 时打开此弹出窗口。这是我想要做的小提琴:jsfiddle.net/qweWa/33 但它没有打开我的弹出窗口
      【解决方案4】:

      试试这个

      function openPopup()
              {
      
                  $('.ajax-call').magnificPopup({
      
                  type: 'inline',
                  modal: true,
      
              });
      
              /*$.magnificPopup({
      
      
      
       type: 'inline',
              modal: false,
      
          });*/
      
          $(document).on('click', '.closePopup', function (e) 
                      {
                          e.preventDefault();
                          $.magnificPopup.close();
                      });
      
          }
      

      【讨论】:

      • 我不想在按钮上绑定它。应该有一个通用函数
      猜你喜欢
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多