jQuery Twitter Bootstrap 模式 - IsShown

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8755561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:59:44  来源:igfitidea点击:

Twitter Bootstrap Modal - IsShown

jquerymodal-dialogtwitter-bootstrap

提问by Marco Johannesen

Hello Fellow SO users,

各位 SO 用户,您好,

Got this problem where i auto populate a modal box.

在我自动填充模态框时遇到了这个问题。

Sometimes it already has content, so i tried doing a hide/show on each request. But the show is fired before the hide function is done, so it breaks the script.

有时它已经有内容,所以我尝试对每个请求进行隐藏/显示。但是 show 在隐藏功能完成之前被触发,所以它破坏了脚本。

I can't do a bind to "hidden", because if it's the first time - it won't fire the hidden function from bootstrap.

我不能绑定到“隐藏”,因为如果这是第一次 - 它不会从引导程序中触发隐藏功能。

Using modal('true') i can see the object has a isShown element, but does anyone know how i can access it?

使用 modal('true') 我可以看到对象有一个 isShown 元素,但有谁知道我如何访问它?

The console.log shows this:

console.log 显示:

$backdrop
    [div.modal-backdrop]

$element
    [div#modal-from-dom.modal]

isShown
    true

settings
    Object { backdrop="static", keyboard=true, show=false}

hide
    function()

show
    function()

toggle
    function()

__proto__
    Object { toggle=function(), show=function(), hide=function()}

回答by dr.dimitru

Answer for Twitter Bootstrap 3:

Twitter Bootstrap 3 的答案:

$("element").data()['bs.modal'].isShown

or

或者

$("element").data('bs.modal').isShown

回答by Marco Johannesen

The answer is:

答案是:

$("element").data('modal').isShown

回答by Smith

On bootstrap 3.0.x

在引导程序 3.0.x 上

  $('#modal_Id').data().modal.isShown

or

或者

  $('#modal_Id').data('modal').isShown

modal_id is the id of your modal

modal_id 是你的模态的 id

回答by ruffin

If you'd like a Bootstrap version 2 and3 solutionand would rather not hit the data(since it looks like the name already changed once)...

如果您想要 Bootstrap 版本 23 解决方案并且不想点击data(因为它看起来名称已经更改过一次)...

$(element).hasClass('in')(would be "faded in" or "visible"; a plus that it returns a boolean)

$(element).hasClass('in')(将“淡入”或“可见”;加上它返回一个布尔值)

or

或者

"false" === $(element).attr('aria-hidden')(so that's aria-hidden or visible as well. "true"for hidden in this case.)

"false" === $(element).attr('aria-hidden')(所以这也是 aria-hidden 或可见的。"true"在这种情况下是隐藏的。)

See source from bootstrap 3.3.1 here:

在此处查看bootstrap 3.3.1 的源代码

this.backdrop(function () {
...
  that.$element
    .addClass('in')
    .attr('aria-hidden', false)
...

Again, that code is from 3.3.1. Can confirm this also works in 2.1.0. Duck sniffing [sic] is probably better in this case.

同样,该代码来自 3.3.1。可以确认这也适用于 2.1.0。在这种情况下,鸭子嗅探 [原文如此] 可能更好。

回答by Tim S

Answer for Bootstrap 4:

Bootstrap 4 的答案:

$("element").data('bs.modal')._isShown

As a function:

作为一个函数:

function isModalShown(modal) {
    var modalIsShown = (modal.data('bs.modal') || {})._isShown;
    return !(typeof modalIsShown === 'undefined' || !modalIsShown);
}