jQuery可折叠

jQuery可折叠,jquery,Jquery,我正在尝试创建一个无序列表,其中每个列表都包含另一个无序列表。我想触发子菜单向下滑动的列表项有class mobile collapse,子菜单有class mobile drop menu。以下是我的jquery代码: <script> $(function() { $(".mobile-drop-menu").hide(); $(".mobile-collapse").click(function() { $(this).children().slideToggle()

我正在尝试创建一个无序列表,其中每个列表都包含另一个无序列表。我想触发子菜单向下滑动的列表项有class mobile collapse,子菜单有class mobile drop menu。以下是我的jquery代码:

<script>
$(function() {
$(".mobile-drop-menu").hide();
$(".mobile-collapse").click(function() { 
    $(this).children().slideToggle();
});
});


</script>
但当我测试它并点击手机时,它消失了。这里有一个链接来测试它。您必须将窗口大小拖到相当小的位置,才能显示无序列表


有人能帮我解决这个问题或找到更好的方法来实现这个目标吗?谢谢

您的列表在这张表格中

<li class="mobile-collapse"><a href="#">Services</a>
        <ul class="mobile-drop-menu">
            <li><a href="#">International Students</a></li>
            <li><a href="#">Teacher Employment</a></li>
            <li><a href="#">Diverse Populations</a></li>
        </ul>
因此,将函数改为:您需要使用find-escaping搜索列表


你的名单在这张表格里

<li class="mobile-collapse"><a href="#">Services</a>
        <ul class="mobile-drop-menu">
            <li><a href="#">International Students</a></li>
            <li><a href="#">Teacher Employment</a></li>
            <li><a href="#">Diverse Populations</a></li>
        </ul>
因此,将函数改为:您需要使用find-escaping搜索列表


Jquery滑动切换只需使用 显示:块或显示:无以显示或隐藏元素

$(this).children().slideToggle();
这将对包含链接的mobile collapse类的所有子元素进行操作。所以我们需要过滤掉link元素

您可以更改行: $this.children.slideToggle; 到 $this.children.mobile-drop-menu.slideToggle


希望这能奏效

Jquery滑动切换只需使用 显示:块或显示:无以显示或隐藏元素

$(this).children().slideToggle();
这将对包含链接的mobile collapse类的所有子元素进行操作。所以我们需要过滤掉link元素

您可以更改行: $this.children.slideToggle; 到 $this.children.mobile-drop-menu.slideToggle


希望这能奏效

@MattAltepeter对你的评价也很高:你实际上教了我很多关于响应式网页设计的知识:@MattAltepeter对你的评价也很高:你实际上教了我很多关于响应式网页设计的知识: