close/hide 单击子菜单

close/hide submenu on click

我一直在试验一个特定的网站,一切看起来都和我想要的一样。我有一个有选择的下拉菜单。然后我有一个点击打开的子菜单。我需要将子菜单放在它所做的下拉菜单之上。然后我需要在 "Return to Menu" link 所在的位置单击关闭子菜单,但保持下拉菜单打开。

我已经到了 "Return to Menu" link 没有关闭整个下拉菜单的地步,但它以前什么都不做,它每次都关闭整个下拉菜单我点开了。

另一个问题是,当我单击子菜单中的其他 link 之一时,通过关闭下拉菜单它可以正常工作,但是当单击下拉按钮时它不会刷新并且一直显示子菜单。

不确定这是否可以完成,我是 JS 的新手,我已经尝试了相当多的 JS 设置 lot.The 当前的 JS 可能不正确,所以请忽略它,或者如果我必须调整它有点。我创建了一个 fiddle 来向您展示我的意思,如果它无法完成,我感谢您花时间和精力帮助我。

这是我的代码。

HTML

    window.onload=function(){
      
//Dropdown Start
$(document).ready(function() {
  $('.dropdown-menu a.dropdown-list').on("click", function(e) {
    $(this).parent().parent().find('.dropdown-list').show();
    $(this).next('li').toggle();
    e.stopPropagation();
  });
});
// Dropdown End


    }
     /* Body Start */
body {
  background-color: #b3d1ff ;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

/* Body End */

/* ============================================================================ */

/* Navbar Start */
.nav-text {
  color: #000 !important;
  font-size: 14px;
  margin-bottom: 5px;
}

.navbar {
  background: rgba (153, 153, 153, 0.5);
  position: fixed;
  height: 45px;
  bottom: 0;
  left: 0;
  width: 100% !important;
}

.navbar .right-text {
  float: right;
  margin: 0;
  margin-right: 10px;
}

/* Navbar End */

/* ============================================================================ */
button:focus {
  outline: none !important;
}


.button {
  background: transparent !important;
  background-color: transparent !important;
  border: none;
}

.dropup {
  left: 0 !important;
}

.dropdown-menu.columns-2 {
  min-width: 600px;
}

.dropdown-menu.columns-3 {
  min-width: 600px;
}

.dropdown-menu li a {
  padding: 5px 15px;
  font-weight: 300;
}



.3-column-drop {
  list-style: none !important;
}

.3-column-drop li a {
  display: inline-block;
  clear: both;
  line-height: 1.428571429;
  color: #333;
  white-space: normal;
}

ul {
  list-style-type: none;
}

/* Dropside Start */

.dropside-submenu {
  position: relative;
}

.dropside-submenu .dropdown-menu {
  width: 740px !important;
  height: 340px !important;
  top: 0;
  left: -548px !important;
 
  background-color: #d9d9d9;
}

/* Dropside End */



/* Dropup End */
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="robots" content="noindex, nofollow">
  <meta name="googlebot" content="noindex, nofollow">
  <meta name="viewport" content="width=device-width, initial-scale=1">


    <link rel="stylesheet" type="text/css" href="/css/result-light.css">

      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/jquery-3.3.1.js"></script>
      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/bootstrap.js"></script>
      <link rel="stylesheet" type="text/css" href="https://www.denlyncomputers.com.au/test/bootstrap.css">
      <link rel="stylesheet" type="text/css" href="https://www.denlyncomputers.com.au/test/styles.css">
      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/custom.js"></script>

  <style id="compiled-css" type="text/css">

/* Dropup Start */
.dropdown-menu {
  width: 740px !important;
  height: 350px !important;
  margin-bottom: 7px !important;
  margin-left: 1px !important;
  background-color: #d9d9d9;
}
  </style>
</head>
<body>
    

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Navbar Start -->
<div class="os">
  <div class="navbar">

    <!-- Menu Start -->
    <div class="dropup show">
      <button class="" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        <img src="https://www.denlyncomputers.com.au/test/start-here.png" width="30" height="30" title="">
      </button>





      <div class="dropdown-menu multi-column columns-3 show" aria-labelledby="dropdownMenuButton">
        <div class="col-12">
          <div class="row">

            <div class="col-4">
              <ul class="3-column-drop">
                <li>
                  <h5>Section1</h5>
                </li>

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>

              </ul>
            </div>

            <div class="col-4">
              <ul class="3-column-drop">
                <li>
                  <h5>Section2</h5>
                </li>

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>

              </ul>
            </div>

            <div class="col-4">
              <ul class="3-column-drop">

                <!-- ====================================== -->
                <!-- Start of Dropside Issue -->
                <!-- ====================================== -->

                <div class="dropside-submenu">
                  <a class="dropdown-item dropdown-list" href="#">
                    <h5> Go To Submenu
                      <img src="https://www.denlyncomputers.com.au/test/arrow.png" width="10" height="11"></h5>
                  </a>

                  <ul class="dropdown-menu">

                    <li><a class="dropdown-item dropdown-list">
                        <h5> Return to Menu
                          <img src="https://www.denlyncomputers.com.au/test/arrow.png" width="10" height="11"></h5>
                      </a>
                    </li>

                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>

                  </ul>
                </div>

                <!-- ====================================== -->
                <!-- End of Dropside Issue -->
                <!-- ====================================== -->

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
              </ul>
            </div>

          </div>
        </div>
      </div>

    </div>
  </div>
</div>

<!-- Menu End -->
<!-- Navbar End -->

</body></html>

https://jsfiddle.net/Denlyn/9hbLgd80/

欢迎使用 Whosebug @Denlyn。

我对您的代码添加了一些最小的更改。认为它应该工作。

    window.onload=function(){
      
//Dropdown Start
$(document).ready(function() {
  $('.dropdown-menu a.dropdown-list').on("click", function(e) {
    $(this).parent().parent().find('.dropdown-list').show();
    $(this).next('li').toggle();
    e.stopPropagation();
  });

  $('.return-link').on('click', function() {
    $('.submmenu').hide();
  });

$('.go-to-submenu').on('click', function() {
    $('.submmenu').show();
});
});
// Dropdown End


    }
     /* Body Start */
body {
  background-color: #b3d1ff ;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

/* Body End */

/* ============================================================================ */

/* Navbar Start */
.nav-text {
  color: #000 !important;
  font-size: 14px;
  margin-bottom: 5px;
}

.navbar {
  background: rgba (153, 153, 153, 0.5);
  position: fixed;
  height: 45px;
  bottom: 0;
  left: 0;
  width: 100% !important;
}

.navbar .right-text {
  float: right;
  margin: 0;
  margin-right: 10px;
}

/* Navbar End */

/* ============================================================================ */
button:focus {
  outline: none !important;
}


.button {
  background: transparent !important;
  background-color: transparent !important;
  border: none;
}

.dropup {
  left: 0 !important;
}

.dropdown-menu.columns-2 {
  min-width: 600px;
}

.dropdown-menu.columns-3 {
  min-width: 600px;
}

.dropdown-menu li a {
  padding: 5px 15px;
  font-weight: 300;
}



.3-column-drop {
  list-style: none !important;
}

.3-column-drop li a {
  display: inline-block;
  clear: both;
  line-height: 1.428571429;
  color: #333;
  white-space: normal;
}

ul {
  list-style-type: none;
}

/* Dropside Start */

.dropside-submenu {
  position: relative;
}

.dropside-submenu .dropdown-menu {
  width: 740px !important;
  height: 340px !important;
  top: 0;
  left: -548px !important;
 
  background-color: #d9d9d9;
}

/* Dropside End */



/* Dropup End */
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="robots" content="noindex, nofollow">
  <meta name="googlebot" content="noindex, nofollow">
  <meta name="viewport" content="width=device-width, initial-scale=1">


    <link rel="stylesheet" type="text/css" href="/css/result-light.css">

      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/jquery-3.3.1.js"></script>
      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/bootstrap.js"></script>
      <link rel="stylesheet" type="text/css" href="https://www.denlyncomputers.com.au/test/bootstrap.css">
      <link rel="stylesheet" type="text/css" href="https://www.denlyncomputers.com.au/test/styles.css">
      <script type="text/javascript" src="https://www.denlyncomputers.com.au/test/custom.js"></script>

  <style id="compiled-css" type="text/css">

/* Dropup Start */
.dropdown-menu {
  width: 740px !important;
  height: 350px !important;
  margin-bottom: 7px !important;
  margin-left: 1px !important;
  background-color: #d9d9d9;
}
  </style>
</head>
<body>
    

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Navbar Start -->
<div class="os">
  <div class="navbar">

    <!-- Menu Start -->
    <div class="dropup show">
      <button class="" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        <img src="https://www.denlyncomputers.com.au/test/start-here.png" width="30" height="30" title="">
      </button>





      <div class="dropdown-menu multi-column columns-3 show" aria-labelledby="dropdownMenuButton">
        <div class="col-12">
          <div class="row">

            <div class="col-4">
              <ul class="3-column-drop">
                <li>
                  <h5>Section1</h5>
                </li>

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>

              </ul>
            </div>

            <div class="col-4">
              <ul class="3-column-drop">
                <li>
                  <h5>Section2</h5>
                </li>

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>

              </ul>
            </div>

            <div class="col-4">
              <ul class="3-column-drop">

                <!-- ====================================== -->
                <!-- Start of Dropside Issue -->
                <!-- ====================================== -->

                <div class="dropside-submenu">
                  <a class="dropdown-item dropdown-list go-to-submenu" href="#">
                    <h5> Go To Submenu
                      <img src="https://www.denlyncomputers.com.au/test/arrow.png" width="10" height="11"></h5>
                  </a>

                  <ul class="dropdown-menu submmenu">

                    <li><a class="dropdown-item dropdown-list return-link">
                        <h5> Return to Menu
                          <img src="https://www.denlyncomputers.com.au/test/arrow.png" width="10" height="11"></h5>
                      </a>
                    </li>

                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>
                    <li><a class="dropdown-item" href="#">Another submenu action</a></li>

                  </ul>
                </div>

                <!-- ====================================== -->
                <!-- End of Dropside Issue -->
                <!-- ====================================== -->

                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
                <li><a href="#">link</a></li>
              </ul>
            </div>

          </div>
        </div>
      </div>

    </div>
  </div>
</div>

<!-- Menu End -->
<!-- Navbar End -->

</body></html>