使用 Bootstrap 向按鈕新增下拉選單


要向按鈕新增下拉選單,只需將按鈕和下拉選單包裝到 .btn-group 中即可。

你可以嘗試執行以下程式碼向按鈕中新增下拉選單 −

範例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <div class = "btn-group">
         <button type = "button" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">
            Default
            <span class = "caret"></span>
         </button>
         <ul class = "dropdown-menu" role = "menu">
            <li><a href = "#">Action</a></li>
            <li><a href = "#">Another action</a></li>
            <li><a href = "#">Something else here</a></li>
            <li class = "divider"></li>
            <li><a href = "#">Separated link</a></li>
         </ul>
      </div>
      <div class = "btn-group">
         <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">
            Primary
            <span class = "caret"></span>
         </button>
         <ul class = "dropdown-menu" role = "menu">
            <li><a href = "#">Action</a></li>
            <li><a href = "#">Another action</a></li>
            <li><a href = "#">Something else here</a></li>
            <li class = "divider"></li>
            <li><a href = "#">Separated link</a></li>
         </ul>
      </div>
   </body>
</html>

更新日期: 12-Jun-2020

330 瀏覽

開啟您的 職業生涯

透過完成學習來獲得認證

開始
廣告
© . All rights reserved.