2014-12-29 21 views
2

主頁面包含Google地圖(div),從地圖中選擇狀態後,我會嘗試打開引導模式並在引導程序中加載選定的縣地圖。如何清除以前的數據,同時打開引導模式?

首次單擊德州狀態(JavaScript ShowModalDialog()調用),然後引導模態警報顯示德克薩斯然後關閉。 第二次選擇俄亥俄州,現在第一次警報顯示德克薩斯州,然後俄亥俄州。

爲什麼以前的狀態顯示在這裏?

<script type="text/javascript"> 
 
      function ShowModalDialog(stateid) { 
 

 
       $('#myModal').modal('show').on('shown.bs.modal', function() { 
 
        
 
        alert(stateid); 
 
        
 
        $("#myModal #myModalLabel").html(document.getElementById("statename").value); 
 
        var datajson = GetCountyData(stateid); 
 

 
       }); 
 

 

 
      } 
 
     </script>
<!-- Modal --> 
 
     <div class="modal fade modal-wide" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
 
      <div class="modal-dialog" style="color: #808080"> 
 
       <div class="modal-content"> 
 
        <div class="modal-header"> 
 
         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
         <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
 

 
        </div> 
 
        <div class="modal-body"> 
 
         .... 
 
         .... 
 
         .. 
 
         . 
 
         </div> 
 
</div> 
 
      </div> 
 
     </div>    

+0

的'on'調用需要拿出了'show'調用之前。 IOW,您必須在觸發相關事件之前設置事件處理程序。 – cvrebert

+0

另外,您可能需要'one'而不是'on'。 – cvrebert

回答

0

我認爲這是在引導錯誤,因爲我有幾種方法來清除模式

$('body').on('hidden.bs.modal', '.modal', function() { 
    $(this).removeData('bs.modal'); 
}); 

但還是老樣子沒有得到「完美」 solutin,becasue與每一個新的呼叫,在屏幕上的模態會比在螢火蟲中有點下降,我看到有很多模態,那裏只是隱藏,比我發現

http://bootboxjs.com/

和我所有的問題都解決了

$("#myModal").on("hide", function() { // remove the event listeners when the dialog is dismissed 
     $("#myModal a.btn").off("click"); 
    }); 

    $("#myModal").on("hidden", function() { // remove the actual elements from the DOM when fully hidden 
     $("#myModal").remove(); 
    }); 

    $("#myModal").modal({     // wire up the actual modal functionality and show the dialog 
     "backdrop" : "static", 
     "keyboard" : true, 
     "show"  : true      // ensure the modal is shown immediately 
    }); 
+0

我需要添加這些腳本嗎?它意味着在$('#myModal')。modal('show')。on('shown.bs.modal',function()..在ShowModalDialog函數中的行嗎? –