Change Bootstrap modal backdrop settings while open

北城以北 提交于 2019-12-04 05:26:32

Try changing modal's option as below:

$('#myModal').data('bs.modal').options.backdrop = 'static';

Here's the working example

For anyone attempting to do this on v4, you need to change:

$("#myModal").data('bs.modal').options.backdrop = 'static';

to

$("#myModal").data('bs.modal')._config.backdrop = 'static';

why don't you just initialize the modal with options at page load instead of on button click?

just define a document ready fn and put the below code in it.

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
  })

You could try something like this: http://codepen.io/bwobst/pen/GrKBKy?editors=1010

$('#open-modal').click(function(evt) {
  $('#myModal').modal({backdrop: 'static'});
  $('.modal button').prop('disabled', true);
});

When you click the 'open modal' button it sets the backdrop to static and disables the buttons within the modal.

I came up with a solution. The issue is that even if you set the backdrop to static, there is still a click listener.

My solution is here. https://jsfiddle.net/25zbf094/2/

JavaScript

$('#makeIndismissable').click(function(){
  $('#myModal').prop('onclick',null).off('click');
});

$('#close').click(function(){
    $('#myModal').modal("hide")
})

I kept the HTML mostly unchanged, but added the id of "close" to the close button. And as you can see above, you can still close the modal by pressing the X in the top right.

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