简体   繁体   English

Bootstrap下拉菜单停留在展开位置,不响应按钮

[英]Bootstrap dropdown menu stuck in expanded position, doesn't respond to button

I'm trying to make a simple sign in program for use in a podium at my office. 我正在尝试制作一个简单的登录程序,以便在我的办公室的讲台上使用。 All that this program is responsible for is allowing clients to put in their name, username, description of their problem, and click submit. 该程序负责的全部工作是允许客户输入他们的姓名,用户名,问题描述,然后单击“提交”。 this information will then get put into a CSV. 然后将这些信息放入CSV。

This all works fine, however the Bootstrap 4 dropdown menu I have included is always stuck open. 一切正常,但是我包含的Bootstrap 4下拉菜单始终处于打开状态。 It defaults to expanded when the page loads, and remains open regardless of clicking the button or not. 当页面加载时,它默认为展开状态,并且无论是否单击按钮,它都保持打开状态。

My code is almost exactly the same as the example code shown on Bootstraps site: 我的代码与Bootstraps站点上显示的示例代码几乎完全相同:

 <div class="row">
     <div class="col-sm">
        <div class="dropdown">
           <button class="btn btn-secondary btn btn-block dropdown-toggle" type="button" id="dropdownMenuButton"
              data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Reason for your visit
           </button>
           <div class="col-sm">
              <div class="dropdown-menu" aria-labelledby="dropdownMenuButton" style="display: block">
                 <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Dropoff')">Scantron dropoff</a>
                 <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Pickup')">Scantron pickup</a>
                 <a class="dropdown-item" href="javascript:dropDownSelection('Wifi issues')">Wifi issues</a>
                 <a class="dropdown-item" href="javascript:dropDownSelection('DUO Enrollment issues')">DUO Enrollment issues</a>
                 <a class="dropdown-item" href="javascript:dropDownSelection('Password Issues')">Password issues</a>
              </div>
           </div>
        </div>
     </div>
  </div>

And here are my imports: 这是我的进口货:

<script src="node_modules/jquery/dist/jquery.js"></script>
<link rel="stylesheet" 
href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="custom.css">

这是显示正在发生的情况的屏幕截图

EDIT: This issue seems to only exist within the Electron/Node.JS enviornment. 编辑:这个问题似乎只存在于Electron / Node.JS环境中。 running my html/css within chrome (by launching the index.html file) works as expected and does not show any errors in the developer console. 在Chrome中运行我的html / css(通过启动index.html文件)可以按预期工作,并且在开发人员控制台中不会显示任何错误。

You have to import bootstraps.bundle.js , too. 您还必须导入bootstraps.bundle.js Otherwise it will not toggle: 否则它将不会切换:

<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>

take note that you're importing jquery before importing boottsraps js-file 请注意,您在导入boottsraps js文件之前先导入jquery


You also have to remove style="display: block" from your dropdown-menu. 您还必须从下拉菜单中删除style="display: block" This display: block; display: block; is the reason why your menu stucks in expanded position. 这就是菜单停留在扩展位置的原因。

 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <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://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js" integrity="sha384-pjaaA8dDz/5BgdFUPX6M/9SUZv4d12SUPF0axWc+VRZkx5xU3daN+lYb49+Ax+Tl" crossorigin="anonymous"></script> <!-- imported jquery, bootstraps css and bootstraps bundle.js --> <div class="row"> <div class="col-sm"> <div class="dropdown"> <button class="btn btn-secondary btn btn-block dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Reason for your visit </button> <div class="col-sm"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <!-- removed style="display: block;" --> <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Dropoff')">Scantron dropoff</a> <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Pickup')">Scantron pickup</a> <a class="dropdown-item" href="javascript:dropDownSelection('Wifi issues')">Wifi issues</a> <a class="dropdown-item" href="javascript:dropDownSelection('DUO Enrollment issues')">DUO Enrollment issues</a> <a class="dropdown-item" href="javascript:dropDownSelection('Password Issues')">Password issues</a> </div> </div> </div> </div> </div> 

"the Bootstrap 4 dropdown menu I have included is always stuck open" “我包含的Bootstrap 4下拉菜单始终处于打开状态”

The dropdown remains "open" because it has inline style "style:display:block" . 下拉列表保持“打开”状态,因为它具有内联样式"style:display:block" Remove this and follow the normal dropdown structure ... 删除它并遵循正常的下拉菜单结构 ...

     <div class="col-sm">
            <div class="dropdown">
                <button class="btn btn-secondary btn btn-block dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Reason for your visit
                </button>
                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                    <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Dropoff')">Scantron dropoff</a>
                    <a class="dropdown-item" href="javascript:dropDownSelection('Scantron Pickup')">Scantron pickup</a>
                    <a class="dropdown-item" href="javascript:dropDownSelection('Wifi issues')">Wifi issues</a>
                    <a class="dropdown-item" href="javascript:dropDownSelection('DUO Enrollment issues')">DUO Enrollment issues</a>
                    <a class="dropdown-item" href="javascript:dropDownSelection('Password Issues')">Password issues</a>
                </div>
            </div>
     </div>

Demo: https://www.codeply.com/go/ViKYGOigbL 演示: https//www.codeply.com/go/ViKYGOigbL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM