Bootstrap modal - close modal when “call to action” button is clicked

后端 未结 5 1920
一向
一向 2021-02-06 20:36

I have a external link inside my modal, and I want the modal to hide after the user has clicked on the link. How do I do that?

Here is my code:

5条回答
  •  逝去的感伤
    2021-02-06 21:02

    You need to bind the modal hide call to the onclick event.

    Assuming you are using jQuery you can do that with:

    $('#closemodal').click(function() {
        $('#modalwindow').modal('hide');
    });
    

    Also make sure the click event is bound after the document has finished loading:

    $(function() {
       // Place the above code inside this block
    });
    enter code here
    

提交回复
热议问题