jQuery 检测可见但隐藏的元素
我找不到正确的选择器
这看起来应该相当容易 - 但根据文档, (http://api.jquery.com/hidden-selector/ 和 http:// api.jquery.com/visible-selector/)...
元素可以被视为隐藏,原因如下:
祖先元素被隐藏,因此该元素不会显示在页面上。
我想检测的是“这个元素是可见的,但包含在隐藏的父元素中”。即,如果我使父元素可见,则该元素也将可见。
This seems like it should be fairly easy - but I can't find the right selector for it
According to the docs (http://api.jquery.com/hidden-selector/ and http://api.jquery.com/visible-selector/)...
Elements can be considered hidden for several reasons:
An ancestor element is hidden, so the element is not shown on the page.
What I want to detect is "this element is visible, but is contained in a hidden parent". Ie, if I made the parent visible, this element would also be visible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这是您常用的内容,请制作自己的选择器:) 这是一个示例:
您可以像这样使用它,测试标记:
使用示例:
或者,您可以使用
.filter()
函数如下:If this is something you'll commonly use, make your own selector :) Here's an example:
You can use it like this, test markup:
Examples of use:
Alternatively, you can use the
.filter()
function like this:现在 jQuery 已经内置了这一切
jQuery has this all built-in nowdays
如果它是您正在查找的特定元素,那么您可以检查它的显示属性
如果它不是特定元素,那么您可以使用 :hidden 找到隐藏的父节点,然后使用自定义函数来查找该元素的节点输入你想要的。
例如,
如果你想要一个干净的选择器,那么我认为你会运气不好,因为我不认为你想要的是 CSS 规范的一部分,所以不会作为 jQuery 中的选择器出现。
If it is a specific element that you are looking for then you could check it's display property
If it wasn't a specific element then you could find the parent nodes that are hidden using :hidden then use a custom function to look for nodes of the type you want.
E.g.
If you want a clean selector then i think that you're going to be out of luck as i don't think what you want is part of the CSS spec, so won't be there as a selector in jQuery.