【问题标题】:jQuery - show only current ul (using a tags as the click rather than li's)jQuery - 仅显示当前 ul(使用标签作为点击而不是 li)
【发布时间】:2011-08-29 14:43:09
【问题描述】:

我正在尝试在以下导航中显示/隐藏子 ul's。在 Aleksi Yrttiaho 的帮助下,我设法让它工作起来。

然后我意识到我没有将列表项编码为我的 jsFiddle 中的链接,并且一旦我的功能坏了,有人可以帮我让它再次工作吗?

This jsFiddle 是正确的标记,但功能不起作用

This is the old markup(基本上是一个标签),你可以看到它工作

所以唯一的区别是我希望函数在点击链接时运行,而不是点击 li。

非常感谢, 红色

【问题讨论】:

    标签: jquery navigation toggle html-lists children


    【解决方案1】:

    试试看

    $("nav li").find("ul").hide().end().find("a")
    // hide all other ul's in the nav
    .click(function(e) {
        $(this).parent().siblings().find('ul').fadeOut('fast');
        $(this).parent().children('ul').delay(200).fadeToggle('fast');
    });
    

    http://jsfiddle.net/866UZ/

    【讨论】:

      【解决方案2】:

      在您的标记中,您应该将nav 中的所有li 包含在ul 标记中。因为 li 应该始终位于 ul 标记内。而且您的选择器也是nav ul li,它将在nav 中查找ul 标签,这就是它没有按预期工作的原因。

      看看这个我已经修复的工作演示。

      http://jsfiddle.net/6Dh8j/24/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-24
        • 1970-01-01
        • 2015-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多