jQuery - 如何选择隐藏/可见元素? [英] jQuery - How to select hidden/visible elements?

查看:91
本文介绍了jQuery - 如何选择隐藏/可见元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做多步形式,我有5个div(所有这些都隐藏)
其中五个是表单的一部分所以我可以通过这样做得到第一个和最后一个div

I'm trying to do multistep form, and I have 5 div's (all of them hidden) The five of them are parts of a form so I can get the first and the last div by doing this

  var first = $("#new").children(":first").next();
  var last = $("#back").prev('div');

#new是表单的id,#back是表单的id按钮。
单击NEXT按钮后,它显示first.next(); ,但它应该只在第一次工作,然后它应该显示可见的div的next()。

"#new" is the id of the form, and "#back" the id of the back button. After click on the NEXT button it shows first.next(); , but it should only work the first time then it should display the next() of the div that is visible.

我怎样才能得到那个div?

How can I get that div?

谢谢

编辑:
我正在尝试这样做,因为我在第一个div上点击下一个
然后它显示第二个div,然后是第三个,所以,
但是我想做一个自动检测其中一个可见的函数。

I'm trying to do this because after I click next on the first div then it shows the second div, and after that the third an so on, but I want to do a function where it automatically detects wich one is visible.

推荐答案

您的问题有点令人困惑,但如果您想检查某个元素是否可见,那么您可以使用:hidden 伪选择器:

Your question got a bit confusing but if you want to check if an element is visible then you can use the :hidden pseudo selector:

var first = $("#new").children(":first").nextAll(':hidden');

并且只查找可见元素:

var first = $("#new").children(":first").nextAll(':visible');

的文档:隐藏 http://api.jquery.com/hidden-selector/

的文档:可见 http://api.jquery.com/visible-selector/

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

注意我使用了 .nextAll ()而不是 .next()因为后者只查找单个下一个元素,前者查看后面的所有兄弟元素根选择。

Notice I used .nextAll() instead of .next() because the latter only looks for the single next element and the former looks at all the sibling elements that come after the root selection.

的文档.nextAll() http://api.jquery.com/nextall

这篇关于jQuery - 如何选择隐藏/可见元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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