1. 程式人生 > >HTML中表頭固定

HTML中表頭固定

準備:先去官方網站下載外掛包,datatable需要jQuery,所以還要提前下載jQuery外掛。

HTML中æä¹æ表头åºå®

  1. 引入檔案:

    <link rel="stylesheet" type="text/css" href="datatables.css">

      <script type="text/javascript" language="javascript" src="jquery-1.12.4"></script>

      <script type="text/javascript" language="javascript" src="datatables.js"></script>

  2. javascript程式碼:

    <script type="text/javascript" class="init">

    $(document).ready(function() {

    $('#example').DataTable( {

    "scrollY":        "300px",

    "scrollCollapse": true,

    "paging":         false

    } );

    } );

    </script>

  3. table部分程式碼:

     <table id="example" class="display">

    <thead>

    <tr>

    <th>學號</th>

    <th>姓名</th>

    <th>班級</th>

    <th>科目</th>

    <th>分數</th>

    <th>排名</th>

    </tr>

    </thead>

    <tbody>

    <tr>

    <td>1</td>

    <td>小明</td>

    <td>三年級一班</td>

    <td>數學</td>

    <td>90</td>

    <td>9</td>

    </tr>

    ......

  4. 5

    效果如圖所示

  5. HTML中æä¹æ表头åºå®