jQuery div显示如果阻止jquery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2083147/
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-26 12:43:41  来源:igfitidea点击:

div display if block jquery

jqueryhtml

提问by Rickstar

i am trying trying to find out if a div style display is block then do something here is an e.g

我试图找出一个 div 样式显示是否被阻止,然后在这里做一些事情,例如

this is just a guess i am tryng to do it in jquery

这只是一个猜测,我想在 jquery 中做到这一点

 if("#toshow":"display" == "block"){

 }else{

 }

回答by BalusC

So you want to distinguish between display: blockand display: none? If so, you can better use the is()function in combination with the :visibleselector for this:

所以你想区分display: blockdisplay: none?如果是这样,您可以更好地将此is()功能与:visible选择器结合使用:

if ($('#toshow').is(':visible')) {

} else {

}

This works regardless of if you used display: block, or display: inline, or display: inline-block.

无论您是否使用display: block, or display: inline, or ,这都有效display: inline-block

回答by Brian McKenna

You need to use the cssfunction.

您需要使用该css功能。

if($("#toshow").css("display") == "block"){

}else{

}

回答by anomareh

$(document).ready(function(){
    if ($('#toshow').css('display') == 'block') {
        // Do something.
    } else {
        // Do something else.
    }
});

Should do the trick.

应该做的伎俩。

回答by Sampson

Don't forget your :visibleselector.

不要忘记您的:visible选择器。

if ($("#toshow:visible").length) {
  // it's visible
} else {
  // it's not visible
}

回答by Hugo Matos de Souza

This option worked perfectly. I am Brazilian and I had to translate the text, but when I saw the code I immediately saw that it was the correct option.

这个选项工作得很好。我是巴西人,我不得不翻译文本,但是当我看到代码时,我立即发现这是正确的选项。

function reversoObjeto() {
  $('#janela').fadeToggle(500, function(e) {
    if ($("#janela").css("display") == "none") {
      alert("Janela Apagou!");
    } else {
      alert("Janela Acendeu!");
    }
  })
}