Javascript 延迟后显示 Bootstrap 模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27394729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing Bootstrap modal after a delay
提问by Stanley Tan
How can I show a Bootstrap modal after 2 seconds without triggering the modal via a button?
如何在 2 秒后显示 Bootstrap 模式而不通过按钮触发模式?
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
回答by jogesh_pi
Assume you have loaded the bootstrap js file, Use setTimeout()Event. Also take a look on bootstrap docs
假设你已经加载了 bootstrap js 文件,使用setTimeout()事件。也看看引导文档
setTimeout(function() {
$('#myModal').modal();
}, 2000);
回答by Arvs
$(window).load(function(){
setTimeout(function(){
$('#myModal').modal('show');
}, 2000);
});
This is how I use it when I prefer it to automatically trigger on page load.
当我更喜欢它在页面加载时自动触发时,这就是我使用它的方式。

