使用 jquery 检查 div 是否隐藏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8484251/
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
Check div is hidden using jquery
提问by cyberfly
This is my div
这是我的 div
<div id="car2" style="display:none;"></div>
Then I have a Show button that will show the div when you click:
然后我有一个显示按钮,当您单击时将显示 div:
$("show").click(function() {
$("$car2").show();
});
So right now I want to check if the div #car2
is still hidden before form submission:
所以现在我想#car2
在提交表单之前检查 div是否仍然隐藏:
if($('#car2').is(':hidden')) {
alert('car 2 is hidden');
}
Now here is the problem. Although the div #car2
already show, I still got alert message which means that jQuery assumes the div #car2
is still hidden.
现在问题来了。尽管 div#car2
已经显示,但我仍然收到警报消息,这意味着 jQuery 假定 div#car2
仍然隐藏。
My jQuery version is 1.7.
我的 jQuery 版本是 1.7。
Thanks.
谢谢。
EDIT:
编辑:
As jasper said, my code is correct and can be run via this demo.
正如 jasper 所说,我的代码是正确的,可以通过这个demo运行。
What i suspect there is some conflict with jquery form to wizard pluginthat i am using with my form. Anyone have any idea to solve this?
我怀疑我在表单中使用的jquery 表单与向导插件存在一些冲突。任何人有任何想法来解决这个问题?
回答by Jasper
You can check the CSS display
property:
您可以检查 CSSdisplay
属性:
if ($('#car').css('display') == 'none') {
alert('Car 2 is hidden');
}
Here is a demo: http://jsfiddle.net/YjP4K/
这是一个演示:http: //jsfiddle.net/YjP4K/
回答by Omtara
Try:
尝试:
if(!$('#car2').is(':visible'))
{
alert('car 2 is hidden');
}
回答by Sadikhasan
Try
尝试
if($('#car2').is(':hidden'))
{
alert('car 2 is hidden');
}
回答by Phil.Wheeler
Try checking for the :visible property instead.
尝试检查 :visible 属性。
if($('#car2').not(':visible'))
{
alert('car 2 is hidden');
}
回答by smendola
回答by SharK
You can use,
您可以使用,
if (!$("#car-2").is(':visible'))
{
alert('car 2 is hidden');
}