bootstrap 雙層模態窗關閉問題

一、頁面概況

二、問題點

  1. 點擊modal “關閉”按鈕後,父modal“關閉”按鈕失效
  2. 點擊modal 右上角“X”後,父modal會一同關閉

三、解決方法

  1. 重寫子modal的hide 觸發事件 hide.bs.modal

    // modal所在的html 的<body>標籤前面加上
    $(function(){
    		$('#myModal').on('hide.bs.modal', function (e) {
    			$("#myModal .modal-body").empty();
    		});
    	});
    
  2. 子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">&times;</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");
    	}
    
  3. 父modal一般方式實現即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章