I Want When User Click On One DropDown All Other open DropDown Get Closed . I looked for answer in google but that is not working for my dropdown i know it's simple but i am unable to this pls help me !!

我希望用户点击一个DropDown所有其他打开DropDown关闭。我在谷歌寻找答案,但这不适用于我的下拉菜单我知道这很简单,但我无法帮助我!

<div class="hh_drop_down">
<ul class="hh_main">

   <li class="hh_main_menu">
    <a href="javascript:void(0);" class="hh_sf">Chemicals</a>
     <ul class="hh_inner">
        <li><a href="#">Additives / Boosters</a></li>
        <li><a href="#">Anti-Allergen</a></li>
        <li><a href="#">Concrete</a></li>
    </ul>
  </li>

  <li  class="hh_main_menu" >
    <a class="hh_sf" href="#">Equipment</a>
      <ul class="hh_inner">
        <li><a href="#">Deodorization</a></li>
        <li><a href="#">Duct Cleaning Equipment</a></li>
        <li><a href="#">Hard Surface</a></li>
     </ul>

  </li>

   <li  class="hh_main_menu" >
     <a class="hh_sf" href="#">Accessories</a>
      <ul class="hh_inner">
          <li><a href="#">Bonnets/Pads</a></li>
          <li><a href="#">Brush/Rake/Sponge</a></li>
        <li><a href="#">Carpet Rakes</a></li>
      </ul>
   </li>

</ul>
</div>

And jquery i am using in this :

我正在使用的jquery:

<script>
 $(document).ready(function(){
     $(".hh_main").on('click' , '.hh_sf' , function(event){
       event.preventDefault();
        if($(this).next().hasClass('hh_inner')) { 
        $(this).next().slideToggle();
     }
   });
});
</script>

1 个解决方案

#1


1

Try this:

HTML:

<div class="hh_drop_down">
    <ul class="hh_main">

        <li class="hh_main_menu">
            <a href="javascript:void(0);" class="hh_sf">Chemicals</a>
            <ul class="hh_inner expanded">
                <li><a href="#">Additives / Boosters</a></li>
                <li><a href="#">Anti-Allergen</a></li>
                <li><a href="#">Concrete</a></li>
            </ul>
        </li>

        <li class="hh_main_menu">
            <a class="hh_sf" href="#">Equipment</a>
            <ul class="hh_inner expanded">
                <li><a href="#">Deodorization</a></li>
                <li><a href="#">Duct Cleaning Equipment</a></li>
                <li><a href="#">Hard Surface</a></li>
            </ul>

        </li>

        <li class="hh_main_menu">
            <a class="hh_sf" href="#">Accessories</a>
            <ul class="hh_inner expanded">
                <li><a href="#">Bonnets/Pads</a></li>
                <li><a href="#">Brush/Rake/Sponge</a></li>
                <li><a href="#">Carpet Rakes</a></li>
            </ul>
        </li>

    </ul>
</div>

JQuery:

<script>
    $(document).ready(function () {
        $(".hh_sf").next().addClass("collapsed").slideUp();

        $(".hh_main").on('click', '.hh_sf', function (event) {
            event.preventDefault();
            var currentClass = $(this).next().prop('class');
            if (currentClass == "hh_inner expanded") {
                $(this).next().removeClass("expanded");
                $(this).next().addClass("collapsed");
                $(this).next().slideUp();
            } else {
                $(".expanded").slideUp().addClass("collapsed").removeClass("expanded");

                $(this).next().removeClass("collapsed");
                $(this).next().addClass("expanded");
                $(this).next().slideDown();
            }

        });
    });
</script>

JsFiddle

更多相关文章

  1. 单击它时,为什么下拉菜单不在我的导航栏中工作?
  2. 等待执行所有ajax回调的最佳解决方案
  3. 无法使用jquery将活动类添加到当前选定的菜单
  4. JQuery的。简单的下拉选择菜单行为问题
  5. 【问题解决方案】ImportError: No module named 'pygal'
  6. 4th,Python三级菜单
  7. Python 黏包及黏包解决方案
  8. 无法安装ndg-httpsclient或者我的解决方案错误
  9. Linux无法连接网络解决方案

随机推荐

  1. Linux FFmpeg 编译so动态库
  2. 如何使用virtualenv安装wxPython
  3. Bash命令在启动时没有找到rvm, Mint
  4. Linux设备驱动剖析之Input(三)
  5. Linux和Windows下查看、设置环境变量的比
  6. 这个冬天,他们实现了梦想中的华丽转身…
  7. 在Linux中的脚本中安装应用程序
  8. linux shell 里面,真值为0,假值为非0
  9. linux 多线程基础
  10. linux 内核协议栈