乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Bootstrap之表格checkbox復選框全選

       WindySky 2016-05-17

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

      效果圖:



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

      1. <table class="table table-bordered table-hover">  
      2.     <thead>  
      3.         <tr class="success">  
      4.             <th>類別編號</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>機車</td>  
      15.             <td>機車</td>  
      16.             <td>有效</td>  
      17.             <td>機車頭</td>  
      18.         </tr>  
      19.         <tr>  
      20.             <td>C00002</td>  
      21.             <td>車廂</td>  
      22.             <td>機車</td>  
      23.             <td>有效</td>  
      24.             <td>載客車廂</td>  
      25.         </tr>  
      26.     </tbody>  
      27. </table>  
      重點是JS的實現(xiàn)。復選框很小,不容易點到,所以點擊每一行也可以選中該行,并用高亮一些CSS樣式表示。點擊復選框所在單元格也能選中復選框。下面是完整代碼和注釋說明:

      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個meta標簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! -->  
      9.         <title>表格</title>  
      10.         <meta name="keywords" content="表格">  
      11.         <meta name="description" content="這真的是一個表格" />  
      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>類別編號</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>機車</td>  
      57.                             <td>機車</td>  
      58.                             <td>有效</td>  
      59.                             <td>機車頭</td>  
      60.                         </tr>  
      61.                         <tr>  
      62.                             <td>C00002</td>  
      63.                             <td>車廂</td>  
      64.                             <td>機車</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.                 /*將全選/反選復選框添加到表頭最前,即增加一列*/  
      103.                 $thr.prepend($checkAllTh);  
      104.                 /*“全選/反選”復選框*/  
      105.                 var $checkAll = $thr.find('input');  
      106.                 $checkAll.click(function(event){  
      107.                     /*將所有行的選中狀態(tài)設成全選框的選中狀態(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ā)點擊操作*/  
      116.                     event.stopPropagation();  
      117.                 });  
      118.                 /*點擊全選框所在單元格時也觸發(fā)全選框的點擊操作*/  
      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.                 /*每一行都在最前面插入一個選中復選框的單元格*/  
      125.                 $tbr.prepend($checkItemTd);  
      126.                 /*點擊每一行的選中復選框時*/  
      127.                 $tbr.find('input').click(function(event){  
      128.                     /*調(diào)整選中行的CSS樣式*/  
      129.                     $(this).parent().parent().toggleClass('warning');  
      130.                     /*如果已經(jīng)被選中行的行數(shù)等于表格的數(shù)據(jù)行數(shù),將全選框設為選中狀態(tài),否則設為未選中狀態(tài)*/  
      131.                     $checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);  
      132.                     /*阻止向上冒泡,以防再次觸發(fā)點擊操作*/  
      133.                     event.stopPropagation();  
      134.                 });  
      135.                 /*點擊每一行時也觸發(fā)該行的選中操作*/  
      136.                 $tbr.click(function(){  
      137.                     $(this).find('input').click();  
      138.                 });  
      139.             }  
      140.             initTableCheckbox();  
      141.         });  
      142.         </script>  
      143.     </body>  
      144.   
      145. </html>  

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約