如何切换列表子列表子列表…与jQuery


How to toggle list sublist sublist ... with jQuery?

我基本上是一个PHP开发人员,我被jQuery困住了。我可以在页面上以列表的形式显示目录中的所有文件。我想在它们上添加切换效果比如当我们点击文件夹时它会滑动其中的所有文件。但它们是动态的,每个文件夹中可能有数百个。这是我做的JS小提琴演示。我已经粘贴了HTML版本的我的代码到这个提琴。jQuery部分:

$(document).ready(function (e) {
    $('.directory').find('ul').hide();
    $('.directory').click(function (e) {
        $(this).children().show('fast');
    });
});
$(document).ready(function(e) {
  $(".directory").click(function(event) {
    event.stopPropagation();
    $(this).children('ul').toggle('fast');
  });
});

这就行了:)