使用jQuery检查div是否隐藏 [英] Check div is hidden using jquery

查看:199
本文介绍了使用jQuery检查div是否隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的div

<div id="car2" style="display:none;"></div>

然后我有一个显示"按钮,当您单击以下按钮时将显示div:

Then I have a Show button that will show the div when you click:

$("show").click(function() {
    $("$car2").show();
}); 

现在,我想检查在提交表单之前div #car2是否仍然隐藏:

So right now I want to check if the div #car2 is still hidden before form submission:

if($('#car2').is(':hidden')) {
    alert('car 2 is hidden');
}

现在是问题所在.尽管div #car2已经显示,但我仍然收到警报消息,这意味着jQuery假定div #car2仍处于隐藏状态.

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.

我的jQuery版本是1.7.

My jQuery version is 1.7.

谢谢.

正如贾斯珀所说,我的代码是正确的,可以通过此演示来运行.

As jasper said, my code is correct and can be run via this demo.

我怀疑与 jquery表单有冲突到我正在与表单一起使用的向导插件.有人有解决这个问题的想法吗?

What i suspect there is some conflict with jquery form to wizard plugin that i am using with my form. Anyone have any idea to solve this?

推荐答案

您可以检查CSS display属性:

You can check the CSS display property:

if ($('#car').css('display') == 'none') {
    alert('Car 2 is hidden');
}

这是一个演示: http://jsfiddle.net/YjP4K/

这篇关于使用jQuery检查div是否隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆