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
div display if block jquery
提问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: block
and display: none
? If so, you can better use the is()
function in combination with the :visible
selector for this:
所以你想区分display: block
和display: 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
回答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 :visible
selector.
不要忘记您的: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!");
}
})
}