2

我有一个div元素<div id='someId' style="visibility: hidden;"></div>

$(#someId).css('可见性'); // 返回“隐藏” $(#someId).is(':hidden'); // 返回错误 $(#someId).is(':visible'); // 返回真

这是 JQuery 1.8 中的错误还是我没有弄清楚?

4

4 回答 4

3

:hidden选择器可以指:

  • display: none
  • type="hidden"
  • width: 0px; height: 0px
  • 祖先元素被隐藏。

所以visibility: hidden在这些情况下不进入。

请参阅此处的 jQuery 文档:http: //api.jquery.com/hidden-selector/

编辑

检查visibility属性:

if($("#someId").css('visibility') == 'hidden') {
   /* some code */
}
于 2012-08-21T10:10:10.187 回答
2

请参考以下 jquery 链接:

:隐藏选择器

:可见选择器

这里清楚地提到了具有可见性的元素:隐藏或不透明度:0 被认为是可见的,因为它们仍然占用布局中的空间

于 2012-08-21T10:13:21.560 回答
1

来自 jquery.com:

Elements can be considered hidden for several reasons:

They have a CSS display value of none.
They are form elements with type="hidden".
Their width and height are explicitly set to 0.
An ancestor element is hidden, so the element is not shown on the page.
于 2012-08-21T10:10:00.590 回答
0

is(':visible') 和 is('hidden') 以 display 属性为参考

于 2012-08-21T10:12:11.933 回答