2016-07-25 50 views
1

我有兩個模態id1和id2,我想打開其中一個模式根據槳切換的狀態。當開關處於'off-state'時,帶id'id1'的Modal需要打開當開關處於「開啓狀態」時,需要打開id爲'id2'的Modal。目前在'onChange'事件上,我添加了需要打開'模擬打開'和'唱腔控制'屬性的模式ID。Bootstrap模態切換

$('#button-id1').attr('data-open', 'id1'); 
$('#button-id1').attr('aria-controls', 'id2'); 

但是這只是第一次,當我關閉打開的模式,切換槳顯示以前打開的模態。 任何人都可以給我一個想法是什麼在這裏?

回答

0

試試這個

$('#id1').modal("hide"); 

它應該是在if語句當開關處於接通狀態的模式的選擇ID應該是要隱藏或者刪除模式是關閉狀態

if(switch_button == on_state){ 
    $('#id1').modal("show"); 
    $('#id2').modal("hide"); 
}else{ 
    $('#id1').modal("hide"); 
    $('#id2').modal("show"); 
} 

如果你不明白你需要放置什麼條件。只是如果,如果有一類開放或任何

if($('#switch_button').hasClass('open')){} 

如果你不想直接打開該模式時,開關被改變,你可以修改它裏面的if語句

if(switch_button == on_state){ 
    $('button1 of the first modal').click(function(){ 
     $('#id1').modal("show"); 
     $('#id2').modal("hide"); 
    }); 
}else{ 
    $('button2 of the second modal').click(function(){ 
     $('#id1').modal("hide"); 
     $('#id2').modal("show"); 
    }); 
} 

和開關按鈕確保你的模態有一個modal-lg類型,用於大型模態-md用於中型和模態-sm用於小型,以查看你的模態是不同的大小。

<!-- Large Modal Format --> 
     <div class="modal fade" id="large" tabindex="-1" role="dialog" aria-hidden="true"> 
      <div class="modal-dialog modal-lg"> 
       <div class="modal-content"> 
        <!-- Modal Content Here --> 
       </div> 
      </div> 
     </div> 

     <!-- Medium Modal Format --> 

     <div class="modal fade" id="medium" tabindex="-1" role="dialog" aria-hidden="true"> 
      <div class="modal-dialog modal-md"> 
       <div class="modal-content"> 
        <!-- Modal Content Here --> 
       </div> 
      </div> 
     </div> 

     <!-- Small Modal Format --> 
     <div class="modal fade" id="small" tabindex="-1" role="dialog" aria-hidden="true"> 
      <div class="modal-dialog modal-sm"> 
       <div class="modal-content"> 
        <!-- Modal Content Here --> 
       </div> 
      </div> 
     </div> 
     <!-- End Modal --> 
+0

開關狀態改變後我無法立即打開模式,我有另一個打開模式的按鈕。問題是按鈕並不總是按照開關狀態顯示模式,它只是第一次工作。 – suresh726

+0

這兩種模態的區別是什麼? –

+0

他們是兩個完全不同的模式,比如「School Form Modal」和另一個是「College Form Modal」。 – suresh726