admin管理员组

文章数量:1391960

I have a bootstrap modal which I open via javascript:

$('#myModal').modal('show');
$('.modal-content').load("page.html");

In order to close the modal, I trigger this code:

$("div#myModal.modal.fade").trigger("click");

My problem is that when the modal is closed, nothing in the page can be clicked again.

Any ideas?

I have a bootstrap modal which I open via javascript:

$('#myModal').modal('show');
$('.modal-content').load("page.html");

In order to close the modal, I trigger this code:

$("div#myModal.modal.fade").trigger("click");

My problem is that when the modal is closed, nothing in the page can be clicked again.

Any ideas?

Share edited Jul 18, 2017 at 13:19 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Jul 18, 2017 at 13:02 rakipirakipi 392 silver badges9 bronze badges 3
  • 1 use .hide(), or .modal('hide') – KingCoder11 Commented Jul 18, 2017 at 13:04
  • Can you show the full code please ? – Himanshu Upadhyay Commented Jul 18, 2017 at 13:04
  • In Simple English, If you are manually trigger the click event for close the modal. some events and css rules could be not working properly. So bootstrap already provide the method for hide the modal box as well. you just use .modal('hide'). Syntax like that $('your element id').modal('hide') – Sudharsan S Commented Jul 18, 2017 at 13:12
Add a ment  | 

2 Answers 2

Reset to default 8

The issue is because you're only hiding the modal UI, you're not clearing the overlay behind the modal which catches mouse events and stops them.

To do what you require, use Bootstrap's built in method for closing the modal instead of triggering the click on the .fade element:

$('#myModal').modal('hide')

.modal('hide')

Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the hidden.bs.modal event occurs).

why not closing the modal in the same way you opened

$('#myModal').modal('hide')

本文标签: javascriptUnable to click anything after closing Bootstrap modalStack Overflow