使用 jQuery 检查 div 是否隐藏
这是我的 div
<div id="car2" style="display:none;"></div>
然后我有一个显示按钮,当您点击时会显示 div:
$("show").click(function() {
$("$car2").show();
});
所以现在我想检查 div #car2
在表单提交之前是否仍然隐藏:
if($('#car2').is(':hidden')) {
alert('car 2 is hidden');
}
现在这是问题。尽管 div #car2
已经显示,但我仍然收到警报消息,这意味着 jQuery 假定 div #car2
仍然隐藏。
我的 jQuery 版本是 1.7。
谢谢。
编辑:
正如贾斯珀所说,我的代码是正确的,可以通过这个演示< /a>.
我怀疑与 jQuery 表单向导有一些冲突我在表单中使用的插件。有人有办法解决这个问题吗?
This is my div
<div id="car2" style="display:none;"></div>
Then I have a Show button that will show the div when you click:
$("show").click(function() {
$("$car2").show();
});
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');
}
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.
My jQuery version is 1.7.
Thanks.
EDIT:
As jasper said, my code is correct and can be run via this demo.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以检查 CSS
display
属性:这是一个演示:http://jsfiddle.net/YjP4K/
You can check the CSS
display
property:Here is a demo: http://jsfiddle.net/YjP4K/
尝试:
Try:
尝试
Try
尝试检查 :visible 属性。
Try checking for the :visible property instead.
您是否注意到您的拼写错误,
$car2
而不是#car2
?无论如何,
:hidden
似乎按预期工作,请在此处尝试一下。Did you notice your typo,
$car2
instead of#car2
?Anyway,
:hidden
seems to be working as expected, try it here.你可以使用,
You can use,