2017-02-20 40 views
0

我遇到了一個模式問題,我有一個,當我關閉它時我需要運行一些東西,實際上當它關閉時,我需要刷新index.php。在模態隱藏時做些事

<!DOCTYPE html> 
<html> 
<head> 
    <script src="js/jquery.min_2.1.4.js"></script> 
    <script src="js/bootstrap3.3.min.js"></script> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" /> 

    <script> 

    $('#myModal').modal({ 
     'show': false 
    }); 


    $('#btnModal').click(function() { 

     $('#myModal').modal('show'); 
    }); 

    $('#myModal').on('hide', function(e) { 
     if (!confirm('You want to close me?')) 
     e.preventDefault(); 
    }); 
    </script> 

    </head> 
<body><!-- Button trigger modal --> 

<button type="button" class="btn btn-success btn-lg" data-toggle="modal" data-target="#myModal"> 
    Launch demo modal 
</button> 

<a role="button" class="btn" id="btnModal">Launch demo modal</a> 

<!-- Modal --> 
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
    <h3 id="myModalLabel">Modal header</h3> 

    </div> 
    <div class="modal-body"> 
    <p>One fine body…</p> 
    </div> 
    <div class="modal-footer"> 
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
    <button class="btn btn-primary">Save changes</button> 
    </div> 
</div> 

</body> 
</html> 

我有這個例子,我不能這樣做的作品。有人可以幫助我嗎? THKS

回答

0

引導有它自己的顯示&隱藏事件名稱:

on('shown.bs.modal',function() { ... })

on('hidden.bs.modal',function() { ... })

希望這有助於。 祝你好運!

UPDATE:更多引導的模態事件名稱:

show.bs.modal:當模式即將被顯示時出現
shown.bs.modal:發生時進行模態盡顯(後CSS轉換已經完成)
hide.bs.modal :當模態即將被隱藏時發生
hidden.bs.modal:當模態被完全隱藏時發生(在CSS過渡完成後)

查看Bootstrap文檔以作進一步參考:http://getbootstrap.com/javascript/#modals-events