Correction status:qualified
Teacher's comments:
普通下拉菜单:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../lib/dist/css/bootstrap.css"> <title>下拉菜单</title> </head> <body> <div class="dropdown"<button type="button" class="btn btn-default" data-toggle="dropdown"> 前端开发 <span class="caret"></span> </button> <ul class="dropdown-menu"> <li class="dropdown-header">常用技术</li> <li><a href="">HTML5</a></li> <li><a href="">CSS3</a></li> <li><a href="">JavaScript</a></li> <li class="divider"></li> <li><a href="">jQuery</a></li> <li><a href="">Bootstrap</a></li> </ul> </div> <script src="../lib/jquery.js"></script> <script src="../lib/dist/js/bootstrap.js"></script> </body> </html>
分裂式菜单:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <!--1. 导入bootstrap样式文件css;--> <link rel="stylesheet" href="../dist/css/bootstrap.css"> <script src="../jquery.js"></script> <script src="../dist/js/bootstrap.js"></script> <title>bootstrap导入</title> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <h3>分裂式下拉菜单</h3> <div class="btn-toolbar"> <div class="btn-group"> <button type="button" class="btn btn-default" data-toggle="dropdown">前端技术</button> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="">H5</a></li> <li><a href="">CSS</a></li> <li><a href="">JS</a></li> <li class="divider"></li> <li><a href="">jQuery</a></li> <li><a href="">Bootstrap</a></li> </ul> </div> </div> </div> </div> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例
个人总结:
data-toggle=“dropdown”存在于那个按钮,那么这个按钮就拥有点击显示下拉的功能。比如上面的这个案例,我只在第二个按钮设置了这个属性,那么只能点击三角区域才会显示下拉菜单,点击“前端技术”则不会,而如果在第一个按钮也设置了这个属性,那么第一个按钮,即“前端技术”也就拥有了这个功能了。