我試圖在加載頁面時啓動模式。問題是我沒有訪問頭部的部分。在頁面加載時啓動模式
我用一個按鈕創建了一個模式。如果我點擊那個按鈕,模式顯示。現在我試圖隱藏按鈕,然後用javascript模擬點擊。我期望那個模式會顯示。但它沒有。
應該「document.getElementById(」hiddenbutton「)。click();」不開火按鈕?
<button id="hiddenbutton" type="button" data-toggle="modal" data-target="#modal_default" style="display: none;"></button>
<!-- Basic modal -->
<div id="modal_default" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h5 class="modal-title">Basic modal</h5>
</div>
<div class="modal-body">
<h6 class="text-semibold">Text in a modal</h6>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
<hr>
<h6 class="text-semibold">Another paragraph</h6>
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- /basic modal -->
<script type="text/javascript">
document.getElementById("hiddenbutton").click();
感謝
嗨。我試過,但後來我得到:「(索引):194 Uncaught ReferenceError:$未定義」 – mitch2k
您使用引導?你包括jQuery庫嗎?單擊該按鈕時該模式是否工作? – Dekel