国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Bootstrap之表格checkbox復(fù)選框全選

版權(quán)聲明:如需轉(zhuǎn)載,請標(biāo)明出處:http://blog.csdn.net/shangmingchao【商明超的博客】

效果圖:



HTML中無需添加額外的一列來表示復(fù)選框,而是由JS完成,所以正常的表格布局就行了:

  1. <table class="table table-bordered table-hover">  
  2.     <thead>  
  3.         <tr class="success">  
  4.             <th>類別編號(hào)</th>  
  5.             <th>類別名稱</th>  
  6.             <th>類別組</th>  
  7.             <th>狀態(tài)</th>  
  8.             <th>說明</th>  
  9.         </tr>  
  10.     </thead>  
  11.     <tbody>  
  12.         <tr>  
  13.             <td>C00001</td>  
  14.             <td>機(jī)車</td>  
  15.             <td>機(jī)車</td>  
  16.             <td>有效</td>  
  17.             <td>機(jī)車頭</td>  
  18.         </tr>  
  19.         <tr>  
  20.             <td>C00002</td>  
  21.             <td>車廂</td>  
  22.             <td>機(jī)車</td>  
  23.             <td>有效</td>  
  24.             <td>載客車廂</td>  
  25.         </tr>  
  26.     </tbody>  
  27. </table>  
重點(diǎn)是JS的實(shí)現(xiàn)。復(fù)選框很小,不容易點(diǎn)到,所以點(diǎn)擊每一行也可以選中該行,并用高亮一些CSS樣式表示。點(diǎn)擊復(fù)選框所在單元格也能選中復(fù)選框。下面是完整代碼和注釋說明:

  1. <!DOCTYPE html>  
  2. <html lang="zh-CN">  
  3.   
  4.     <head>  
  5.         <meta charset="utf-8">  
  6.         <meta http-equiv="X-UA-Compatible" content="IE=edge">  
  7.         <meta name="viewport" content="width=device-width, initial-scale=1">  
  8.         <!-- 上述3個(gè)meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! -->  
  9.         <title>表格</title>  
  10.         <meta name="keywords" content="表格">  
  11.         <meta name="description" content="這真的是一個(gè)表格" />  
  12.         <meta name="HandheldFriendly" content="True" />  
  13.         <link rel="shortcut icon" href="img/favicon.ico">  
  14.         <!-- Bootstrap3.3.5 CSS -->  
  15.         <link href="css/bootstrap.min.css" rel="stylesheet">  
  16.   
  17.         <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->  
  18.         <!--[if lt IE 9]>  
  19.             <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>  
  20.             <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>  
  21.         <![endif]-->  
  22.     </head>  
  23.   
  24.     <body>  
  25.         <div class="panel-group">  
  26.             <div class="panel panel-primary">  
  27.                 <div class="panel-heading">  
  28.                     列表  
  29.                 </div>  
  30.                 <div class="panel-body">  
  31.                     <div class="list-op" id="list_op">  
  32.                         <button type="button" class="btn btn-default btn-sm">  
  33.                             <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增  
  34.                         </button>  
  35.                         <button type="button" class="btn btn-default btn-sm">  
  36.                             <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改  
  37.                         </button>  
  38.                         <button type="button" class="btn btn-default btn-sm">  
  39.                             <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>刪除  
  40.                         </button>  
  41.                     </div>  
  42.                 </div>  
  43.                 <table class="table table-bordered table-hover">  
  44.                     <thead>  
  45.                         <tr class="success">  
  46.                             <th>類別編號(hào)</th>  
  47.                             <th>類別名稱</th>  
  48.                             <th>類別組</th>  
  49.                             <th>狀態(tài)</th>  
  50.                             <th>說明</th>  
  51.                         </tr>  
  52.                     </thead>  
  53.                     <tbody>  
  54.                         <tr>  
  55.                             <td>C00001</td>  
  56.                             <td>機(jī)車</td>  
  57.                             <td>機(jī)車</td>  
  58.                             <td>有效</td>  
  59.                             <td>機(jī)車頭</td>  
  60.                         </tr>  
  61.                         <tr>  
  62.                             <td>C00002</td>  
  63.                             <td>車廂</td>  
  64.                             <td>機(jī)車</td>  
  65.                             <td>有效</td>  
  66.                             <td>載客車廂</td>  
  67.                         </tr>  
  68.                     </tbody>  
  69.                 </table>  
  70.                 <div class="panel-footer">  
  71.                     <nav>  
  72.                         <ul class="pagination pagination-sm">  
  73.                             <li class="disabled">  
  74.                                 <a href="#" aria-label="Previous">  
  75.                                     <span aria-hidden="true">?</span>  
  76.                                 </a>  
  77.                             </li>  
  78.                             <li class="active"><a href="#">1</a></li>  
  79.                             <li><a href="#">2</a></li>  
  80.                             <li><a href="#">3</a></li>  
  81.                             <li><a href="#">4</a></li>  
  82.                             <li><a href="#">5</a></li>  
  83.                             <li>  
  84.                                 <a href="#" aria-label="Next">  
  85.                                     <span aria-hidden="true">?</span>  
  86.                                 </a>  
  87.                             </li>  
  88.                         </ul>  
  89.                     </nav>  
  90.                 </div><!-- end of panel-footer -->  
  91.             </div><!-- end of panel -->  
  92.         </div>  
  93.         <!-- jQuery1.11.3 (necessary for Bo otstrap's JavaScript plugins) -->  
  94.         <script src="js/jquery-1.11.3.min.js "></script>  
  95.         <!-- Include all compiled plugins (below), or include individual files as needed -->  
  96.         <script src="js/bootstrap.min.js "></script>  
  97.         <script>  
  98.         $(function(){  
  99.             function initTableCheckbox() {  
  100.                 var $thr = $('table thead tr');  
  101.                 var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');  
  102.                 /*將全選/反選復(fù)選框添加到表頭最前,即增加一列*/  
  103.                 $thr.prepend($checkAllTh);  
  104.                 /*“全選/反選”復(fù)選框*/  
  105.                 var $checkAll = $thr.find('input');  
  106.                 $checkAll.click(function(event){  
  107.                     /*將所有行的選中狀態(tài)設(shè)成全選框的選中狀態(tài)*/  
  108.                     $tbr.find('input').prop('checked',$(this).prop('checked'));  
  109.                     /*并調(diào)整所有選中行的CSS樣式*/  
  110.                     if ($(this).prop('checked')) {  
  111.                         $tbr.find('input').parent().parent().addClass('warning');  
  112.                     } else{  
  113.                         $tbr.find('input').parent().parent().removeClass('warning');  
  114.                     }  
  115.                     /*阻止向上冒泡,以防再次觸發(fā)點(diǎn)擊操作*/  
  116.                     event.stopPropagation();  
  117.                 });  
  118.                 /*點(diǎn)擊全選框所在單元格時(shí)也觸發(fā)全選框的點(diǎn)擊操作*/  
  119.                 $checkAllTh.click(function(){  
  120.                     $(this).find('input').click();  
  121.                 });  
  122.                 var $tbr = $('table tbody tr');  
  123.                 var $checkItemTd = $('<td><input type="checkbox" name="checkItem" /></td>');  
  124.                 /*每一行都在最前面插入一個(gè)選中復(fù)選框的單元格*/  
  125.                 $tbr.prepend($checkItemTd);  
  126.                 /*點(diǎn)擊每一行的選中復(fù)選框時(shí)*/  
  127.                 $tbr.find('input').click(function(event){  
  128.                     /*調(diào)整選中行的CSS樣式*/  
  129.                     $(this).parent().parent().toggleClass('warning');  
  130.                     /*如果已經(jīng)被選中行的行數(shù)等于表格的數(shù)據(jù)行數(shù),將全選框設(shè)為選中狀態(tài),否則設(shè)為未選中狀態(tài)*/  
  131.                     $checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);  
  132.                     /*阻止向上冒泡,以防再次觸發(fā)點(diǎn)擊操作*/  
  133.                     event.stopPropagation();  
  134.                 });  
  135.                 /*點(diǎn)擊每一行時(shí)也觸發(fā)該行的選中操作*/  
  136.                 $tbr.click(function(){  
  137.                     $(this).find('input').click();  
  138.                 });  
  139.             }  
  140.             initTableCheckbox();  
  141.         });  
  142.         </script>  
  143.     </body>  
  144.   
  145. </html>  
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
學(xué)會(huì)Twitter Bootstrap不再難
Bootstrap富文本編輯器bootstrap
30分鐘快速掌握Bootstrap
詳解Bootstrap中JS插件實(shí)現(xiàn)下拉菜單效果
【學(xué)習(xí)筆記】Bootstrap常用組件整理
前端之jQuery與Bootstrap
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服