在页面加载时启动Bootstrap Modal [英] Launch Bootstrap Modal on page load
本文介绍了在页面加载时启动Bootstrap Modal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根本不懂javascript。 bootstrap文档中提到
I don't know javascript at all. The bootstrap documentation says to
通过javascript调用模态:$('#myModal')。modal(options)
Call the modal via javascript: $('#myModal').modal(options)
我不知道如何在页面加载时调用它。使用引导页面上提供的代码,我可以在单击元素上成功调用Modal,但我希望它可以在页面加载时立即加载。
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.
推荐答案
在文档头部的jQuery load
事件中,将页面加载时要调用的模式包装起来,就会弹出,如下所示:
JS
JS
<script type="text/javascript">
$(window).on('load',function(){
$('#myModal').modal('show');
});
</script>
HTML
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 Modal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文