Can I check if Bootstrap Modal Shown / Hidden?

前端 未结 11 1446
走了就别回头了
走了就别回头了 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 12:59

    In offical way:

    > ($("element").data('bs.modal') || {})._isShown    // Bootstrap 4
    > ($("element").data('bs.modal') || {}).isShown     // Bootstrap <= 3
    

    {} is used to avoid the case that modal is not opened yet (it return undefined). You can also assign it equal {isShown: false} to keep it's more make sense.

提交回复
热议问题