jQuery 切换嵌套列表行为
我有许多嵌套列表和一些 jQuery,当单击父标题时显示隐藏它们。
IT 工作正常,但行为略有错误。如果嵌套列表可见并且单击父标题,我希望隐藏该嵌套列表。目前它执行此操作,但随后直接显示嵌套列表。
请参阅此 jsFiddle 了解工作代码:
I have a number of nested lists and some jQuery that shows hides them when a parent header is clicked.
IT works fine but the behaviour is slightly wrong. If a nested list is visible and the parent header is clicked i would like that nested list to be hidden. At the moment it does this but then shows the nested list directly after.
Please see this jsFiddle for working code:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看这里:
http://www.jsfiddle.net/dactivo/c3vPa/
我们验证它是否可见,在这种情况下我们隐藏它:
这将是代码:
Look here:
http://www.jsfiddle.net/dactivo/c3vPa/
We verify if it is visible, and in that case we hide it:
This would be the code:
如果同级
当前隐藏(有效地使其成为切换),您可以触发显示,如下所示:
您可以在此处进行测试。总的来说,您可以简化它并获得相同的效果,如下所示:
您可以在这里尝试该版本< /a>.
You can trigger the show if the sibling
<ul>
is hidden currently (effectively making it a toggle), like this:You can test it out here. Overall you can slim it down and get the same effect though, like this:
You can try that version out here.