0

下面的代码一次打开两个dropout memu,你能提供解决方案和背后的原因吗?

JSFiddle 链接:http: //jsfiddle.net/jsTDz/

相同的代码复制粘贴在这里:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
  </head>
  <body>
  <div class="btn-group" style="margin:100px;">  
    <a class="btn" href="#">One</span></a>
   <a id="drop1" class="btn dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>  
   <ul class="dropdown-menu" role="menu" aria-labelledby="drop1">
      <li><a tabindex="-1" href="#">Action</a></li>
      <li><a tabindex="-1" href="#">Another action</a></li>
      <li><a tabindex="-1" href="#">Something else here</a></li>
      <li class="dropdown-submenu">
        <a tabindex="-1" href="#">More options</a>
        <ul class="dropdown-menu ">
          <li><a tabindex="-1" href="#">Action</a></li>
          <li><a tabindex="-1" href="#">Another action</a></li>
          <li><a tabindex="-1" href="#">Something else here</a></li>
        </ul>
      </li>
    </ul>    
  <a class="btn" href="#">ClickMe</span></a>
    <a id="drop2" class="btn dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu" aria-labelledby="drop2">
      <li><a tabindex="-1" href="#">One</a></li>
      <li><a tabindex="-1" href="#">Two</a></li>
      <li><a tabindex="-1" href="#">Three</a></li>
    </ul>  
  </div>
  </body>
</html>​
4

1 回答 1

2

您同时删除两个菜单的原因是因为您将两个 UL 放在一个“btn-group”DIV 中。引导 CSS 和 JS 使用“btn-group”类来定位它下面的 UL。既然有两个,两个都火。

为了解决这个问题,将你的第二个 UL 包装在一个带有“btn-group”类的 DIV 中。这样,两组列表将保持相互独立。

最后,您的代码应如下所示:

<div class="btn-group" style="margin:100px;">  
<a class="btn" href="#">One</span></a>
<a id="drop1" class="btn dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>  
<ul class="dropdown-menu" role="menu" aria-labelledby="drop1">
  <li><a tabindex="-1" href="#">Action</a></li>
  <li><a tabindex="-1" href="#">Another action</a></li>
  <li><a tabindex="-1" href="#">Something else here</a></li>
  <li class="dropdown-submenu">
    <a tabindex="-1" href="#">More options</a>
    <ul class="dropdown-menu ">
      <li><a tabindex="-1" href="#">Action</a></li>
      <li><a tabindex="-1" href="#">Another action</a></li>
      <li><a tabindex="-1" href="#">Something else here</a></li>
    </ul>
  </li>
</ul>  
</div>
<div class="btn-group">  
<a class="btn" href="#">ClickMe</span></a>
<a id="drop2" class="btn dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="drop2">
  <li><a tabindex="-1" href="#">One</a></li>
  <li><a tabindex="-1" href="#">Two</a></li>
  <li><a tabindex="-1" href="#">Three</a></li>
</ul>  
</div>
于 2012-12-12T17:33:56.463 回答