延迟后显示Bootstrap模态 [英] Showing Bootstrap modal after a delay

查看:75
本文介绍了延迟后显示Bootstrap模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在2秒后显示一个Bootstrap模态而不通过按钮触发模态?

How can I show a Bootstrap modal after 2 seconds without triggering the modal via a button?

<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">&times;</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>


推荐答案

假设你已经加载了bootstrap js文件,使用< a href =https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout> setTimeout()事件。另请参阅 bootstrap docs

Assume you have loaded the bootstrap js file, Use setTimeout() Event. Also take a look on bootstrap docs

setTimeout(function() {
    $('#myModal').modal();
}, 2000);

这篇关于延迟后显示Bootstrap模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆