【问题标题】:Bootstrap Drop down button not dropping downBootstrap下拉按钮不下拉
【发布时间】:2022-02-16 08:57:13
【问题描述】:

所以我在表格的末尾添加了一个下拉按钮,但由于某种原因,当我单击它时,没有任何内容会下拉。我的控制台上也看不到任何错误。我的 CSS 中有什么东西可能会阻止它工作吗?

HTML 代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="public/stylesheets/grayscale.css">
  <title>tech</title>
</head>

<body>
<div id="Tech" class="header">
  <center><img src="public/images/test.png" id='Logo' alt="Logo">
  </center>
</div>

<form id="upload" action="index.html" method="POST" enctype="multipart/form-data">
<fieldset>
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000" />
<div>
    <div id="filedrag"> 
        <img src="public/images/upload3.png" alt="draganddrop"> 
    </div>
    <input type="file" id="fileselect" name="fileselect[]" multiple="multiple"/>
</div>
</fieldset>
</form>

<div id="messages">
</div>

<table id="data-table" class="container">
  <thead>
    <tr>
      <th>
        <h3>Video</h3>
      </th>
      <th>
        <h3>Original Size</h3>
      </th>
      <th>
        <h3>Compressed Size</h3>
      </th>
      <th>
        <h3>Compressed rate</h3>
      </th>
      <th>
        <h3>Savings</h3>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Video1 File Name</td>
      <td>Original File Size</td>
      <td>6369</td>
      <td>01:32:50</td>
      <td>450</td>      
      <td>
        <div class="container">
          <div class="dropdown">
            <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
            <span class="caret"></span></button>
            <ul class="dropdown-menu">
              <li><a href="#">Compress</a></li>
              <li class="disabled"><a href="#">Download</a></li>
              <li class="active"><a href="#">Delete</a></li>
            </ul>
          </div>
        </div>        
      </td>
    </tr>
    <tr>
      <td>Video 2 File Name</td>
      <td>Original File Size</td>
      <td>10437</td>
      <td>00:51:22</td>
      <td>450</td>
      <td>
        <div class="container">
          <div class="dropdown">
            <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
            <span class="caret"></span></button>
            <ul class="dropdown-menu">
              <li><a href="#">Compress</a></li>
              <li class="disabled"><a href="#">Download</a></li>
              <li class="active"><a href="#">Delete</a></li>
            </ul>
          </div>
        </div>               
      </td>
    </tr>
    <tr>
      <td>Video 3 File Name</td>
      <td>Original File Size</td>
      <td>5327</td>
      <td>00:24:34</td>
      <td>450</td>
      <td>
        <div class="container">
          <div class="dropdown">
            <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
            <span class="caret"></span></button>
            <ul class="dropdown-menu">
              <li><a href="#">Compress</a></li>
              <li class="disabled"><a href="#">Download</a></li>
              <li class="active"><a href="#">Delete</a></li>
            </ul>
          </div>
        </div>        
      </td>
    </tr>
  </tbody>
</table>

</body>
<script src="public/js/filedrag.js"></script>
</html>

CSS 代码:

@charset "UTF-8";
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,400,700);

body {
  font-family: 'Open Sans', sans-serif;
  font-weight: 300;
  line-height: 1.42em;
  color:#A7A1AE;
  background-color:#1F2739;
}

.data-table{
    margin-top: 250px;
}

#filedrag{
    text-align: center;
    border-radius: 7px;
    cursor: default;
}

#filedrag.hover{
    color: #f00;
    border-color: #f00;
    border-style: solid;
    box-shadow: inset 0 3px 4px #888;
}

#title{
    text-align: center;
}

#logo{
    float: right;
}

.header img {
    float:left;
    border: 5px;
    padding:5px;
    width: 4em;
    height: 4em;
    border-radius: 10px;
}

.header h1 {
  position:relative;
  font-size:3em; 
  font-weight: 300;
  line-height:1em;
  text-align: left;
  color: #FFFFFF;
}

h1 {
  font-size:3em; 
  font-weight: 300;
  line-height:1em;
  text-align: center;
  color: #FFFFFF;
}

h2 {
  font-size:1em; 
  font-weight: 300;
  text-align: center;
  display: block;
  line-height:1em;
  padding-bottom: 2em;
  color: #FB667A;
}

h2 a {
  font-weight: 700;
  text-transform: uppercase;
  color: #FB667A;
  text-decoration: none;
}

h3{
    color: white;
}

h4{
    text-align: center;
    font-size: 2em;
}

#Register
{
    margin-left: 750px;
    margin-top: 27px;
}
.btn-update{
    position: absolute;
    bottom: 0;
    margin-bottom: 300px;
    margin-left: -65px;
}

.hideshow{
    position: absolute;
    bottom: 0;
    margin-bottom: 300px;
    margin-left: -65px;
}

.blue { color: #185875; }
.yellow { color: #FFF842; }

.container th h1 {
      font-weight: bold;
      font-size: 1em;
  text-align: left;
  color: #185875;
}

.container td {
      font-weight: normal;
      font-size: 1em;
  -webkit-box-shadow: 0 2px 2px -2px #0E1119;
       -moz-box-shadow: 0 2px 2px -2px #0E1119;
            box-shadow: 0 2px 2px -2px #0E1119;
}

.container {
      text-align: left;
      overflow: hidden;
      width: 80%;
      margin: 0 auto;
  display: table;
  padding: 0 0 8em 0;
}

.container td, .container th {
    padding-bottom: 2%;
    padding-top: 2%;
    padding-left:2%;  
}

/* Background-color of the odd rows */
.container tr:nth-child(odd) {
      background-color: #323C50;
}

/* Background-color of the even rows */
.container tr:nth-child(even) {
      background-color: #2C3446;
}

.container th {
      background-color: #1F2739;
}

.container_graph {
  width: 80%;
  margin: 15px auto;
  margin-top: 175px;
}

.container td:first-child { color: #FB667A; }

.container tr:hover {
   background-color: #464A52;
-webkit-box-shadow: 0 6px 6px -6px #0E1119;
       -moz-box-shadow: 0 6px 6px -6px #0E1119;
            box-shadow: 0 6px 6px -6px #0E1119;
}

.container td:hover {
  /*background-color: #FFF842;*/
  /*color: #403E10;*/


  transition-delay: 0s;
      transition-duration: 0.4s;
      transition-property: all;
  transition-timing-function: line;
}

@media (max-width: 800px) {
.container td:nth-child(4),
.container th:nth-child(4) { display: none; }
}

【问题讨论】:

    标签: jquery html css twitter-bootstrap


    【解决方案1】:

    确保也加载 bootstrap.js,因为下拉菜单需要 bootstrap.js 才能运行。

    css 文件主要是为控件设置样式,但真正的交互是由 JavaScript 文件处理的。

    【讨论】:

    • 对不起,我对此还是有点陌生​​。通过加载 bootstrap.js,你到底是什么意思?编辑:我的主文件夹中有一个从网站下载的引导文件夹,这就是我所要做的吗?
    • Bootstrap 有两个它需要的文件 - bootstrap.css 和 bootstrap.js。您还需要添加加载 bootstrap.js 文件的
    • @KarthikKomatineni getbootstrap.com/getting-started/#download-cdn 从cdn 或本地文件夹加载文件都没有关系。您仍然需要加载所有三个。现在你缺少bootstrap.js(或bootstrap.min.js)——你可以使用它们中的任何一个。确保在 jquery.min.js 之后加载它。
    • 所以我添加了这两行: 还有 .....所以这些是指到我在主文件夹中下载的引导文件,这应该正确吗?
    • 您只需要其中之一。 .min 只是一个缩小(较小的文件大小)版本
    【解决方案2】:

    在结束 &lt;/body&gt; 标记之前添加这些依赖项,

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    

    【讨论】:

    • 你好,请注意这个问题是5年前的问题,它是关于bootstrap V3的。现有答案已经解决了这个问题,我建议删除这个答案。
    • 您好,很棒的评论,但是我不同意您的建议,希望下载新版本的开发人员会发现我的回答有帮助。干杯!
    • 好的,我理解你的好意。如果您可以编辑答案并添加一些介绍,这将很有用,例如“对于那些对 bootstrap V4 有相同问题的人,这是我的解决方案:...”。感谢您的贡献。
    【解决方案3】:

    看看下面的 sn-p 它工作正常。按下面提到的顺序添加 cdn。

    <link rel="stylesheet"   
    href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    

    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
              <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
               <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
               <style type="text/css">
                 
    
               </style>
               </head>
               <body>
               <div id="Tech" class="header">
      <center><img src="public/images/test.png" id='Logo' alt="Logo">
      </center>
    </div>
    
    <form id="upload" action="index.html" method="POST" enctype="multipart/form-data">
    <fieldset>
    <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000" />
    <div>
        <div id="filedrag"> 
            <img src="public/images/upload3.png" alt="draganddrop"> 
        </div>
        <input type="file" id="fileselect" name="fileselect[]" multiple="multiple"/>
    </div>
    </fieldset>
    </form>
    
    <div id="messages">
    </div>
    
    <table id="data-table" class="container">
      <thead>
        <tr>
          <th>
            <h3>Video</h3>
          </th>
          <th>
            <h3>Original Size</h3>
          </th>
          <th>
            <h3>Compressed Size</h3>
          </th>
          <th>
            <h3>Compressed rate</h3>
          </th>
          <th>
            <h3>Savings</h3>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Video1 File Name</td>
          <td>Original File Size</td>
          <td>6369</td>
          <td>01:32:50</td>
          <td>450</td>      
          <td>
            <div class="container">
              <div class="dropdown">
                <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
                <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">Compress</a></li>
                  <li class="disabled"><a href="#">Download</a></li>
                  <li class="active"><a href="#">Delete</a></li>
                </ul>
              </div>
            </div>        
          </td>
        </tr>
        <tr>
          <td>Video 2 File Name</td>
          <td>Original File Size</td>
          <td>10437</td>
          <td>00:51:22</td>
          <td>450</td>
          <td>
            <div class="container">
              <div class="dropdown">
                <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
                <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">Compress</a></li>
                  <li class="disabled"><a href="#">Download</a></li>
                  <li class="active"><a href="#">Delete</a></li>
                </ul>
              </div>
            </div>               
          </td>
        </tr>
        <tr>
          <td>Video 3 File Name</td>
          <td>Original File Size</td>
          <td>5327</td>
          <td>00:24:34</td>
          <td>450</td>
          <td>
            <div class="container">
              <div class="dropdown">
                <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Compress
                <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">Compress</a></li>
                  <li class="disabled"><a href="#">Download</a></li>
                  <li class="active"><a href="#">Delete</a></li>
                </ul>
              </div>
            </div>        
          </td>
        </tr>
      </tbody>
    </table>
      </body>
      </html>

    【讨论】:

    • 刚刚添加了,但由于某种原因,它仍然没有下降。你认为这可能是我的 CSS 中的某些东西阻止了它吗?
    • 不,您的 CSS 没有引用您的下拉按钮。从您的页面中删除所有其他链接文件,即脚本和 css,但 bootstrap cdn 除外。之后运行您的代码,看看是否发生了同样的问题。
    • 是的,我刚刚删除了除引导 cdn 之外的所有内容,它可以正常工作。只需要弄清楚是哪一个给我带来了麻烦。谢谢!
    • 我认为这是你的 javascript 文件..''。我认为它对您的切换按钮有一些参考。希望这会有所帮助!
    • 万一是古玩,那是css代码的溢出部分!
    猜你喜欢
    • 2020-12-02
    • 2018-07-26
    • 2015-06-09
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    相关资源
    最近更新 更多