【问题标题】:Function error from category drop-down button类别下拉按钮的功能错误
【发布时间】:2022-01-17 17:49:28
【问题描述】:

我有这个类别:

当我按下下拉按钮时,它应该只删除一种类型,但这里它同时删除了 3 种类型。我哪里做错了? 这是刀片:

@foreach($loai as $l => $type)
    <ul style="list-style:none">

      <li>
        <span style="font-size: 17px"><a href="{{URL::to('/loai-san-pham/'.$type->type_id)}}">{{$type->type_name}}</a></span>
        
        <span class="items-sidebar">v</span>

      </li>

      @foreach($hang as $h)
          @if($h->brand_type==1)
              <ul class="brand_category">
                  <li>
                      <a href="{{route('hangsanpham',$h->brand_id)}}">{{$h->brand_name}}</a>
                  </li>
              </ul>
          @endif
      @endforeach

      <ul class="type_category" style="display: none"></ul>

    </ul>
@endforeach

这里是下拉功能:

<script type="text/javascript">
    $('.items-sidebar').click(function(){
        $(this).parents('ul').find('.brand_category',).toggle();
    });
    $('.items-sidebar').click(function(){
        $(this).parents('ul').find('.type_category',).toggle();
    });

刀片或js功能有问题吗?请帮忙..

【问题讨论】:

  • 您能否发布在浏览器中显示的下拉列表的 HTML?这样可以更轻松地重现您的问题。

标签: javascript php html laravel


【解决方案1】:

您正在选择所有父母元素的所有品牌类别。 而且您的 find 方法中还有一个不必要的逗号。

试试这个

<script type="text/javascript">
    $('.items-sidebar').click(function(){
        $(this).closest('ul').find('.brand_category').toggle();
    });
    $('.items-sidebar').click(function(){
        $(this).closest('ul').find('.type_category').toggle();
    });
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2013-11-28
    相关资源
    最近更新 更多