test.blade.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>table</title>
  6. </head>
  7. <body>
  8. <table id="table" cellspacing="0" cellpadding="2" width="100%" border="1">
  9. <thead>
  10. <tr >
  11. <th >用户编号</th>
  12. <th>试用时间</th>
  13. <th>转正时间</th>
  14. <th>生日时间</th>
  15. <th>民族</th>
  16. <th>身高</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td>2000001</td>
  22. <td>1997-3-13</td>
  23. <td>1997-3-13</td>
  24. <td>1965-3-13</td>
  25. <td>汉</td>
  26. <td>171</td>
  27. </tr>
  28. <tr>
  29. <td>2000045</td>
  30. <td>2001-2-15</td>
  31. <td>2001-3-15</td>
  32. <td>1978-8-5</td>
  33. <td>汉</td>
  34. <td>162</td>
  35. </tr>
  36. <tr>
  37. <td>2000046</td>
  38. <td>2001-2-23</td>
  39. <td>2001-3-23</td>
  40. <td>2001-2-23</td>
  41. <td>汉</td>
  42. <td>171</td>
  43. </tr>
  44. </tbody>
  45. </table>
  46. <script type="text/javascript">
  47. var tTD; //用来存储当前更改宽度的Table Cell,避免快速移动鼠标的问题
  48. var table = document.getElementById("table");
  49. var down = false;
  50. for (i = 0; i < table.rows[0].cells.length; i++) {
  51. table.rows[0].cells[i].onmousedown = function () {
  52. //记录单元格
  53. tTD = this;
  54. if (event.offsetX > tTD.offsetWidth - 10) {
  55. down = true;
  56. tTD.oldX = event.x;
  57. tTD.oldWidth = tTD.offsetWidth;
  58. }
  59. //记录Table宽度
  60. table = tTD; while (table.tagName != 'TABLE') table = table.parentElement;
  61. tTD.tableWidth = table.offsetWidth;
  62. };
  63. table.rows[0].cells[i].onmousemove = function () {
  64. //更改鼠标样式
  65. if (event.offsetX > this.offsetWidth - 10)
  66. this.style.cursor = 'col-resize';
  67. else
  68. this.style.cursor = 'default';
  69. //取出暂存的Table Cell
  70. if (tTD == undefined) tTD = this;
  71. }
  72. }
  73. document.onmouseup = function () {
  74. if (down) {
  75. //结束宽度调整
  76. if (tTD == undefined) tTD = this;
  77. down = false;
  78. tTD.style.cursor = 'default';
  79. }
  80. };
  81. document.onmousemove = function () {
  82. if (down) {
  83. //调整宽度
  84. if (down) {
  85. tTD.style.cursor = 'default';
  86. if (tTD.oldWidth + (event.x - tTD.oldX) > 0)
  87. tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
  88. //调整列宽
  89. tTD.style.width = tTD.width;
  90. tTD.style.cursor = 'col-resize';
  91. //调整该列中的每个Cell
  92. table = tTD;
  93. while (table.tagName != 'TABLE') table = table.parentElement;
  94. for (i = 0; i < table.rows.length; i++) {
  95. table.rows[i].cells[tTD.cellIndex].width = tTD.width;
  96. }
  97. //调整整个表
  98. table.width = tTD.tableWidth + (tTD.offsetWidth - tTD.oldWidth);
  99. table.style.width = table.width;
  100. }
  101. }
  102. };
  103. </script>
  104. </body>
  105. </html>