在页面加载时启动 Bootstrap 模式 [英] Launch Bootstrap Modal on Page Load
问题描述
我根本不懂 JavaScript.Bootstrap 文档说
<块引用>通过 JavaScript 调用模态:$('#myModal').modal(options)
我不知道如何在页面加载时调用它.使用 Bootstrap 页面上提供的代码,我可以在元素点击时成功调用 Modal,但我希望它在页面加载时立即加载.
只需将要在页面加载时调用的模式包装在文档头部部分的 jQuery load
事件中,它应该弹出窗口,如下所示:
JS
HTML
<div class="modal-body"><p>一个精致的身体……</p>
<div class="modal-footer"><a href="#";class=btn">关闭</a><a href="#";class=btn btn-primary">保存更改</a>
您仍然可以通过使用如下链接调用它来调用页面中的模态:
I don't know JavaScript at all. The Bootstrap documentation says to
Call the modal via JavaScript:
$('#myModal').modal(options)
I have no clue how to call this on a page load. Using the supplied code on the Bootstrap page I can successfully call the Modal on an element click, but I want it to load immediately on a page load.
Just wrap the modal you want to call on page load inside a jQuery load
event on the head section of your document and it should popup, like so:
JS
<script type="text/javascript">
$(window).on('load', function() {
$('#myModal').modal('show');
});
</script>
HTML
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<a href="#" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
You can still call the modal within your page with by calling it with a link like so:
<a class="btn" data-toggle="modal" href="#myModal">Launch Modal</a>
这篇关于在页面加载时启动 Bootstrap 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!