2013-11-23 66 views
1

如何在頁面加載時自動加載引導模型?當頁面加載時自動加載引導模式

我嘗試添加以下到我的索引文件:

<script type="text/javascript"> 
    $(window).load(function() { 
     $('#myModal').modal('show'); 
    }); 
</script> 

但它不工作。

+0

你的js控制檯說什麼?如果沒有錯誤,在'$('#myModal')。modal('show');'行上放一個斷點,看它是否被調用。如果它被調用,並且您在腳本控制檯中沒有錯誤,那麼請放置整個源代碼,以便我們可以看到整個圖片。 –

+0

可能你已經在頁面開頭寫了這段代碼..需要在你的模態窗口代碼之後寫下它.so模塊的內容得到執行1st然後它將啓動.. – Ashish

+0

它在窗口的加載事件中,意思是在加載所有內容後執行 –

回答

5

試試這個,它應該工作:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#myModal').modal('show'); 
    }); 
</script> 
+0

我希望這對你有用 –

+2

其不適合我,如果我manualy點擊鏈接到相同的div #myModal它打開對話框.. –

-4

嘗試將作爲默認值

<div class="input-group date" id='dob' name="dob" data-date-format="yyyy-mm-dd" > 
     <input type="text" name="dob" id="dob" ***value="1940-01-01***" maxlength="20" class="form-control" required title="Please enter the date of birth"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span> 
     </div> 

和腳本

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#dob').datepicker({ 
      startDate: '1940-01-01', 
      endDate: '-5d' 
     }) 
    }); 
    </script 
+1

這與OP – Flexicoder

0

建立在形式specifing值黑色行動「的答案,我注意到這可能是解決舊版本的Bootstrap。在新版本中,第一次點擊按鈕時,它會初始化模態。這需要在可以顯示之前發生。因此,不需要:.modal(show),您需要執行:.modal({show:true}),它會初始化模態實例,然後將其設置爲默認顯示。所以:

<script type=\"text/javascript\"> 
    jQuery(document).ready(function() { 
    jQuery('#myModalId').modal({show:true}); 
    }); 
</script> 

您也可以在這些{}中設置模態的其他設置。有關設置詳情,請參見Bootstrap's Model Doc