如果我在模态内调用$("#modal").closeModal();,则不会触发complete方法。我用以下内容打开模态。

$("#modal").openModal({
    dismissible: false,
    complete: this.doSomething
});


我做错什么了吗?有没有一种方法可以触发模式关闭模式内部,从而触发complete方法?我需要等待模态关闭之前发生的事情。

最佳答案

这是你想要的吗?

html文件

  

<!-- Modal Structure -->
<a class="waves-effect waves-light btn modal-trigger" href="#modal1">Modal</a>

<div id="modal1" class="modal">
  <div class="modal-content">

    <!--following line has the icon to close the modal on your command-->

    <h4>Modal Header <i class = "material-icons right" id = "closeIcon">close</i></h4>
    <p>A bunch of text</p>

    <!--following button adds text to the <p> tag with id = "textBody" i.e. its doing something and the modal wont close until that is done-->

    <button class = "btn waves-effect waves-light" id = "doSomething">Press me and do something</button>


  </div>
  <div class="modal-footer">
    <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
  </div>
</div>
<p id = "textBody">

</p>


jQuery的

$(document).ready(function(){
  $('.modal-trigger').leanModal({
    dismissible: false,

    /*waiting for the user to click the button before closing*/
    complete: $('#doSomething').click(function(){

                  $('#textBody').html('i got a Boo Boo');
                  $('#modal1').closeModal();

              })

  });
  $("#closeIcon").click(function(){
    $('#modal1').closeModal();
  });



})


这是检查正在发生的情况的链接:https://jsfiddle.net/4y6ptm8k/4/

关于javascript - 物化closeModal未触发完成,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37731808/

10-16 19:39