4-8 按钮插件--模拟复选按钮
本节编程练习不计算学习进度,请电脑登录imooc.com操作

按钮插件--模拟复选按钮

使用按钮组来模拟复选按钮和模拟单选按钮是一样的,具有同等效果,也是通过在按钮组上自定义data-toggle="buttons"来实现。唯一不同的是,将input[type="radio"]换成input[type="checkbox"],如下所示:

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-primary">
        <input type="checkbox" name="options" id="options1">电影
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" name="options" id="options2">音乐
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" name="options" id="options3">游戏
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" name="options" id="options4">摄影
    </label>
</div>

运行效果如下:

任务

我来试试:补充右侧代码以实现“复选择按钮模似复选按钮组的效果”

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title> </title>
  6. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  7. <style>
  8. body{padding:10px;margin:10px;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="btn-group">
  13. <label class="btn btn-primary">
  14. <input type="checkbox" name="options" id="options1">电影
  15. </label>
  16. <label class="btn btn-primary">
  17. <input type="checkbox" name="options" id="options2">音乐
  18. </label>
  19. <label class="btn btn-primary">
  20. <input type="checkbox" name="options" id="options3">游戏
  21. </label>
  22. <label class="btn btn-primary">
  23. <input type="checkbox" name="options" id="options4">摄影
  24. </label>
  25. </div>
  26. <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
  27. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  28. </body>
  29. </html>
下一节