Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery进行嵌套_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 使用jquery进行嵌套

Javascript 使用jquery进行嵌套,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试使用jQuery制作嵌套的accordion。到目前为止,我做了以下几点: $'.toggle'。单击函数E{ e、 防止违约; var$this=$this; 如果$this.next.hasClass'show'{ $this.next.removeClass'show'; $this.next.slideUp350; }否则{ $this.parent.parent.find'li.inner'。removeClass'show'; $this.parent.parent.fi

我正在尝试使用jQuery制作嵌套的accordion。到目前为止,我做了以下几点:

$'.toggle'。单击函数E{ e、 防止违约; var$this=$this; 如果$this.next.hasClass'show'{ $this.next.removeClass'show'; $this.next.slideUp350; }否则{ $this.parent.parent.find'li.inner'。removeClass'show'; $this.parent.parent.find'li.inner'。幻灯片350; $this.next.toggleClass'show'; $this.next.slideToggle350; } }; Lorem ipsum dolor sit amet,是一位杰出的献身者。马塞纳斯·坦普斯·普拉西拉。杜瓦是一位精英和多洛·劳里特·帕特。阿利奎姆乌尔特里斯莫里斯马蒂斯。埃尼安诅咒乌尔特里斯和瓦里乌斯。阿利奎阿利克达皮布斯酒店 布兰迪特。在hac habitasse Plateum,一句名言。Sed risus velit,Pelletsque eu enim ac,ultricies pretium felis。

子项将在关闭其父项时自动关闭。

选择2
这里有代码:

html:在选项2中,您必须添加一个类选项2

javascript:您必须添加$this.parent.parent.find'li.parentChild'。切换;这两种情况都适用

$('.toggle').click(function (e) {
            e.preventDefault();
            var $this = $(this);
            if ($this.next().hasClass('show')) {
                $this.next().removeClass('show');
                $this.next().slideUp(350);
                $this.parent().parent().find('li .parentChild').toggle();
            } else {
                $this.parent().parent().find('li .inner').removeClass('show');
                $this.parent().parent().find('li .inner').slideUp(350);
                $this.parent().parent().find('li .parentChild').toggle();
                $this.next().toggleClass('show');
                $this.next().slideToggle(350);
            }
        });

您可以在JSFIDLE链接中看到结果:

您可以将ref手风琴添加到代码笔中吗?
ul {
  display:block!important;
  list-style: none;
  padding: 0;
}

ul .inner {
  padding-left: 1em;
  overflow: hidden;
  display: none;
}

ul .inner.show {
  /*display: block;*/
}

ul li {
  margin: .5em 0;
}

ul li a.toggle {
  width: 100%;
  display: block;
  background: rgba(0, 0, 0, 0.78);
  color: #fefefe;
  padding: .75em;
  border-radius: 0.15em;
  transition: background .3s ease;
}

ul li a.toggle:hover {
  background: rgba(0, 0, 0, 0.9);
}
ul li.parentChild{
  display:none;
}
$('.toggle').click(function (e) {
            e.preventDefault();
            var $this = $(this);
            if ($this.next().hasClass('show')) {
                $this.next().removeClass('show');
                $this.next().slideUp(350);
                $this.parent().parent().find('li .parentChild').toggle();
            } else {
                $this.parent().parent().find('li .inner').removeClass('show');
                $this.parent().parent().find('li .inner').slideUp(350);
                $this.parent().parent().find('li .parentChild').toggle();
                $this.next().toggleClass('show');
                $this.next().slideToggle(350);
            }
        });