$(element:visible) 在 $(this) 之前或之后
如何确定 HTML 中 $(element:visible)
是放置在 $(this)
之前还是之后?
我的 HTML 代码如下所示
<div class="wrapper" style="display:none;">
<div class="title">1</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper">
<div class="title">2</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper" style="display:none;">
<div class="title">3</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper" style="display:none;">
<div class="title">4</div>
<div class="text">Lorem Ipsum</div>
</div>
当我单击标题 2 时,我想知道该标题之前是否有可见的 $('.wrapper')
。
How do I determine if $(element:visible)
is placed before or after $(this)
in HTML?
My HTML code looks like this
<div class="wrapper" style="display:none;">
<div class="title">1</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper">
<div class="title">2</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper" style="display:none;">
<div class="title">3</div>
<div class="text">Lorem Ipsum</div>
</div>
<div class="wrapper" style="display:none;">
<div class="title">4</div>
<div class="text">Lorem Ipsum</div>
</div>
When I click on title 2 I want to know if there is visible $('.wrapper')
before that title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我希望这就是您所需要的。
这会告诉您之前的
.wrapper
(单击的标题之前)是否可见。编辑:这解决了您更新的问题
希望这有帮助。干杯
I hope this is what you need
This tells you if the previous
.wrapper
(previous to clicked title) is visible.EDIT: This solves your updated question
Hope this helps. Cheers
总结一下。您需要检查在单击的元素之前是否存在任何具有“wrapper”类的可见元素。
如果是这样的话,应该可以做到这一点。
或者:
To sum it up. You need to check if there are any visible elements with class "wrapper" prior to clicked element.
If that is it, this should do it.
Or:
仅当父级可见时,它才会为您提供父级。
This will give you a parent only if it is visible.
将获得带有类
wrapper
的最接近的父级,这意味着即使$(this)
位于包装器内部较深处,它仍然可以正常运行。Will get the closest parent with a class
wrapper
meaning even if$(this)
is deeper inside the wrapper it will still function properly.如果您想查看是否有任何以前可见的包装纸......
$(this).parent().prev(".wrapper:visible").length()
如果您想查看是否只有前一个可见...
$(this).parent().prev().is(":visible")
If you are looking to see if there is ANY previous visible wrappers...
$(this).parent().prev(".wrapper:visible").length()
If you are looking to see if only the previous one before it is visible...
$(this).parent().prev().is(":visible")