一、頁面概況
二、問題點
- 點擊modal “關閉”按鈕後,父modal“關閉”按鈕失效
- 點擊modal 右上角“X”後,父modal會一同關閉
三、解決方法
-
重寫子modal的hide 觸發事件 hide.bs.modal
// modal所在的html 的<body>標籤前面加上 $(function(){ $('#myModal').on('hide.bs.modal', function (e) { $("#myModal .modal-body").empty(); }); });
-
子modal “關閉”按鈕和右上角“X” 點擊都添加onclick方法
<!-- modal 右上角的“X” 添加onclick觸發事件的方法 --> <div class="modal fade" id="myModal" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg" role="document" style="width:80%"> <div class="modal-content <div class="modal-header"> <button type="button" class="close" onclick="calloff()" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">標題</h4> </div> <div class="modal-body" id="myModalBody"></div> </div> </div> </div>
//onclick 方法的具體實現,右上角的“X”和“關閉”按鈕均調用這個 calloff:function(){ $("#myModal").modal("hide"); }
-
父modal一般方式實現即可