物化closeModal未完成射击

时间:2016-06-09 16:43:50

标签: javascript html typescript angular materialize

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

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

我有什么问题吗?有没有办法触发模态在模态内关闭,以便触发complete方法?在模态关闭之前,我需要等待一些事情发生。

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

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/