How to toggle a bootstrap alert on and off with button click?

前端 未结 9 897
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 21:21

I want to display an alert box multiple times with a button click event without having to refresh the page but the alert box only shows up once. If I want to show the alert box

9条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 22:04

    I've had the same problem: just don't use the data-dismiss from the close button and work with JQuery show() and hide():

    $('.close').click(function() {
       $('.alert').hide();
    })
    

    Now you can show the alert when clicking a button by using the code:

    $('.alert').show()
    

    Hope this helps!

提交回复
热议问题