jQuery - 仅显示当前 ul (使用标签作为点击而不是 li's)
我试图在以下导航中显示/隐藏子ul's
。在 Aleksi Yrttiaho 的帮助下,我设法让它发挥作用。
然后我意识到我没有将列表项编码为 jsFiddle 中的链接,一旦我的功能中断,有人可以帮助我让它再次工作吗?
这个 jsFiddle 是正确的标记,但功能不起作用
这是旧的标记(本质上是前面的标记),您可以看到它正在工作
唯一的区别是我希望该函数在单击链接时运行,而不是单击 li。
非常感谢, 红色的
I am trying to show/hide child ul's
in the following navigation. I managed to get it working with the help of Aleksi Yrttiaho.
I then realised that I hadn't coded the list items as links in my jsFiddle, and as soon as I did the function broke, can someone help me out get it working again?
This jsFiddle is the correct markup but with the function not working
This is the old markup (pre a tags essentially) and you can see it working
So the only difference is that I want the function to run on the click of a link, rather than a click of the li.
Many thanks,
Red
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
http://jsfiddle.net/866UZ/
give this a try
http://jsfiddle.net/866UZ/
在您的标记中,您应该将
nav
内的所有 li 包含在ul
标记中。因为 li 应该始终位于ul
标记内。而且您的选择器也是nav ul li
,它将在nav
内查找ul
标记,这就是它无法按预期工作的原因。看看这个工作演示,我已经修复了它。
http://jsfiddle.net/6Dh8j/24/
In your markup you should enclose all the li's inside
nav
in aul
tag. Because li's should always be inside aul
tag. And your selector is alsonav ul li
which will look forul
tag insidenav
thats whay it was not working as expected.Take a look at this working demo I have fixed it.
http://jsfiddle.net/6Dh8j/24/