簡體   English   中英

Bootstrap下拉列表在PHP Codeigniter中不起作用

[英]Bootstrap dropdown not working in php codeigniter

我下面有html代碼可以使用引導程序在我的網頁中添加下拉菜單。

   <div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
    <button class="dropdown-item" type="button">Action</button>
    <button class="dropdown-item" type="button">Another action</button>
    <button class="dropdown-item" type="button">Something else here</button>
  </div>
</div>

   </div>


   <script src="<?php echo base_url('assets/js/bootstrap.js'); ?>" type="text/javascript"></script>
    <script src="<?php echo base_url('assets/js/jquery-3.2.1.min.js'); ?>"></script>          

    <link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet" type="text/css"/>    
    <link href="<?php echo base_url('assets/css/bootstrap.css'); ?>" rel="stylesheet" type="text/css"/>        

        </body>

運行此代碼,我得到的只是灰色按鈕,單擊按鈕沒有下拉菜單。

我正在使用Codeigntier框架,並已在項目的資產目錄中添加了所有js和css文件

可以請人幫忙嗎?

非常感謝。

注意:我可以在此頁面上將引導程序用於其他控件。 只有下拉菜單似乎有問題。

您需要嘗試使用此代碼而不是下拉代碼。

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" id="menu1" type="button" data-toggle="dropdown">Dropdown Example <span class="caret"></span></button> <ul class="dropdown-menu" role="menu" aria-labelledby="menu1"> <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li> </ul> </body> </html> 

您僅創建了一個錯誤

按照正確的順序放置jquery,首先必須放置jquery核心文件,因為bootstrap js完全取決於jquery core js。

以下是正確的順序

// Place your stylesheet in header with this order

<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="YOUR CUSTOM CSS FILE URL" rel="stylesheet" type="text/css"> //place here your custom style url

// Place your script in footer with this order

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="YOUR CUSTOM JAVASCRIPT FILE URL" type="text/javascript"></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM