Can I check if Bootstrap Modal Shown / Hidden?

前端 未结 11 1445
走了就别回头了
走了就别回头了 2020-12-05 12:29

Can I check if Bootstrap Modal currently Shown / Hidden Programatically?

Like bool a = if(\"#myModal\").shown(); ?

I need true/false

11条回答
  •  既然无缘
    2020-12-05 13:14

    All Bootstrap versions:

    var isShown = $('.modal').hasClass('in') || $('.modal').hasClass('show')
    

    To just close it independent of state and version:

    $('.modal button.close').click()
    

    more info

    Bootstrap 3 and before

    var isShown = $('.modal').hasClass('in')
    

    Bootstrap 4

    var isShown = $('.modal').hasClass('show')
    

提交回复
热议问题