example13.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. #data {
  8. border-collapse: collapse;
  9. }
  10. #data td, #data th {
  11. width: 120px;
  12. height: 40px;
  13. text-align: center;
  14. border: 1px solid black;
  15. }
  16. #buttons {
  17. margin: 10px 0;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <table id="data">
  23. <caption>数据统计表</caption>
  24. <tr>
  25. <th>姓名</th>
  26. <th>年龄</th>
  27. <th>性别</th>
  28. <th>身高</th>
  29. <th>体重</th>
  30. </tr>
  31. <tr>
  32. <td>Item1</td>
  33. <td>Item2</td>
  34. <td>Item3</td>
  35. <td>Item4</td>
  36. <td>Item5</td>
  37. </tr>
  38. <tr>
  39. <td>Item1</td>
  40. <td>Item2</td>
  41. <td>Item3</td>
  42. <td>Item4</td>
  43. <td>Item5</td>
  44. </tr>
  45. <tr>
  46. <td>Item1</td>
  47. <td>Item2</td>
  48. <td>Item3</td>
  49. <td>Item4</td>
  50. <td>Item5</td>
  51. </tr>
  52. <tr>
  53. <td>Item1</td>
  54. <td>Item2</td>
  55. <td>Item3</td>
  56. <td>Item4</td>
  57. <td>Item5</td>
  58. </tr>
  59. <tr>
  60. <td>Item1</td>
  61. <td>Item2</td>
  62. <td><a>Item3</a></td>
  63. <td>Item4</td>
  64. <td>Item5</td>
  65. </tr>
  66. <tr>
  67. <td>Item1</td>
  68. <td>Item2</td>
  69. <td>Item3</td>
  70. <td>Item4</td>
  71. <td><a>Item5</a></td>
  72. </tr>
  73. </table>
  74. <div id="buttons">
  75. <button id="pretty">美化表格</button>
  76. <button id="clear">清除数据</button>
  77. <button id="remove">删单元格</button>
  78. <button id="hide">隐藏表格</button>
  79. </div>
  80. <script src="js/jquery.min.js"></script>
  81. <script>
  82. $(function() {
  83. $("#pretty").on("click", function() {
  84. $("#data tr:gt(0)").css("color", "white");
  85. $("#data tr:odd").css("background-color", "darkgreen");
  86. $("#data tr:even").css("background-color", "darkmagenta");
  87. $("#data tr:eq(0)").css("background-color", "white");
  88. });
  89. $("#clear").on("click", function() {
  90. $("#data tr:gt(0) td").html("");
  91. });
  92. $("#remove").on("click", function() {
  93. $("#data tr:gt(0):last").remove();
  94. });
  95. $("#hide").on("click", function() {
  96. $("#data").fadeOut(2000, function() {
  97. $("#data").css({
  98. "display": "block",
  99. "visibility": "hidden"
  100. });
  101. });
  102. });
  103. });
  104. </script>
  105. </body>
  106. </html>