how2j.cn

效果 说明 示例代码
<!DOCTYPE html>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
 
<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="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</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="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div class="btn-group">
    <button type="button" class="btn btn-success dropdown-toggle "  data-toggle="dropdown">
     success 
      <span class="caret"></span>          
    </button>
     
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div class="btn-group">
    <button type="button" class="btn btn-info dropdown-toggle "  data-toggle="dropdown">
     info 
      <span class="caret"></span>          
    </button>
     
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div class="btn-group">
    <button type="button" class="btn btn-warning dropdown-toggle "  data-toggle="dropdown">
     warning 
      <span class="caret"></span>          
    </button>
     
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div class="btn-group">
    <button type="button" class="btn btn-danger dropdown-toggle "  data-toggle="dropdown">
     danger 
      <span class="caret"></span>          
    </button>
     
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div style="height:100px"></div>
单按钮下拉菜单
示例代码
<!DOCTYPE html>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.0.3/bootstrap.min.css" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
 
<div class="btn-group">
   <button type="button" class="btn btn-default">默认</button>
   <button type="button" class="btn btn-default dropdown-toggle" 
      data-toggle="dropdown">
      <span class="caret"></span>

   </button>
   <ul class="dropdown-menu" role="menu">
     <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
   </ul>
</div>

<div style="height:100px"></div>
分裂式按钮下拉菜单
示例代码
<!DOCTYPE html>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
  
<div class="btn-group">
    <button type="button" class="btn btn-lg btn-default dropdown-toggle " data-toggle="dropdown">
     大号
      <span class="caret"></span>          
    </button>
      
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
  
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 
<div class="btn-group">
    <button type="button" class="btn btn btn-default dropdown-toggle " data-toggle="dropdown">
     默认
      <span class="caret"></span>          
    </button>
      
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
  
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>  
 
<div class="btn-group">
    <button type="button" class="btn btn-sm btn-default dropdown-toggle " data-toggle="dropdown">
     小号
      <span class="caret"></span>          
    </button>
      
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
  
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>  
 
<div class="btn-group">
    <button type="button" class="btn btn-xs btn-default dropdown-toggle " data-toggle="dropdown">
     更小
      <span class="caret"></span>          
    </button>
      
    <ul class="dropdown-menu" role="menu">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
  
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>  
  
<div style="height:100px"></div>
按钮大小
示例代码
<!DOCTYPE html>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
  
<div style="height:150px"></div>

<div class="btn-group dropup">
    <button type="button" class="btn btn-default dropdown-toggle " id="dropdownMenu1" data-toggle="dropdown">
     default
      <span class="caret"></span>          
    </button>
      
    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
      <li>
         <a href="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
  
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    

向上弹出式菜单
示例代码
示例 1 : 单按钮下拉菜单   
示例 2 : 分裂式按钮下拉菜单   
示例 3 : 按钮大小   
示例 4 : 向上弹出式菜单   

示例 1 :

单按钮下拉菜单

单按钮下拉菜单
运行效果
<!DOCTYPE html> <script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script> <link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script> <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="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</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="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-success dropdown-toggle " data-toggle="dropdown"> success <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-info dropdown-toggle " data-toggle="dropdown"> info <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-warning dropdown-toggle " data-toggle="dropdown"> warning <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-danger dropdown-toggle " data-toggle="dropdown"> danger <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div style="height:100px"></div>


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

分裂式按钮下拉菜单

分裂式按钮下拉菜单
运行效果
<!DOCTYPE html> <script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script> <link href="http://how2j.cn/study/css/bootstrap/3.0.3/bootstrap.min.css" rel="stylesheet"> <script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script> <div class="btn-group"> <button type="button" class="btn btn-default">默认</button> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div style="height:100px"></div>


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 3 :

按钮大小

按钮大小
运行效果
<!DOCTYPE html> <script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script> <link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script> <div class="btn-group"> <button type="button" class="btn btn-lg btn-default dropdown-toggle " data-toggle="dropdown"> 大号 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn btn-default dropdown-toggle " data-toggle="dropdown"> 默认 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-sm btn-default dropdown-toggle " data-toggle="dropdown"> 小号 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div class="btn-group"> <button type="button" class="btn btn-xs btn-default dropdown-toggle " data-toggle="dropdown"> 更小 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div> <div style="height:100px"></div>


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 4 :

向上弹出式菜单

向上弹出式菜单
运行效果
<!DOCTYPE html> <script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script> <link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script> <div style="height:150px"></div> <div class="btn-group dropup"> <button type="button" class="btn btn-default dropdown-toggle " id="dropdownMenu1" data-toggle="dropdown"> default <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"> <li> <a href="#">HTML</a> </li> <li role="presentation"> <a href="#">CSS</a> </li> <li role="presentation"> <a href="#">Javascript</a> </li> <li role="presentation"> <a href="#">AJAX</a> </li> </ul> </div>


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


问答区域    
2018-02-26 下拉菜单跟向上弹出菜单的代码有什么不同?
ToohoKing
下拉菜单跟向上弹出菜单的代码有什么不同? 没看出什么区别啊




1 个答案

lmf5103510 答案时间:2018-03-12
<div class="btn-group dropup"> 这一句




答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2017-09-21 这里可以省略id和aria-labelledby吗?不理解
junxiaoge



如标题
<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="#">HTML</a>             
      </li>
      <li role="presentation">
         <a href="#">CSS</a>              
      </li>
 
      <li role="presentation">
         <a href="#">Javascript</a>           
      </li>
      <li role="presentation">
         <a href="#">AJAX</a>             
      </li>
    </ul>
</div>    
 

							






答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到





2017-08-23 下拉菜单没效果
2017-08-01 示例4的默认按钮处多了一个btn
2017-04-26 aria-labelledby="dropdownMenu1"
2017-04-06 为啥第一个li没有加role="presentation"?
2016-12-06 111




提问之前请登陆
关于 前端部分-BootStrap-按钮式下拉菜单 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图