How to always display Bootstrap 3 modal?

微笑、不失礼 提交于 2021-02-08 04:51:25

问题


Bootstrap 3 modals are hidden by default. To launch them I have to click a trigger button:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

JSFiddle

I have tried the following but it has no effect:

jQuery(window).load(function(){
    jQuery('#myModal').modal('show');
});

How can I ensure my modal is always displayed on screen? i.e. I don't want the user to have to manually display it by clicking on the trigger button. I don't want them to be able to close it either. I'd like it to remain open at all times.


回答1:


Here is the updated fiddle where users can't close the model but you need to remove the html elements for close buttons cuz thats very evil for your users :P

jQuery(window).load(function(){
    jQuery('#myModal').modal('show').on('hide.bs.modal', function(e){
      e.preventDefault();
    });
});

http://jsfiddle.net/95Vf7/2/




回答2:


Everything you asked is perfectly described in the docs.

Displayed on screen

Shows the modal when initialized.

$("#my-modal").modal({ show : true });

I don't want them to be able to close it either

Closes the modal when escape key is pressed And Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click.

$("#my-modal").modal({
    backdrop : "static",
    keyboard: false
});


来源:https://stackoverflow.com/questions/23818216/how-to-always-display-bootstrap-3-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!