jquery01.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. #page ul li {
  8. list-style: none;
  9. width: 240px;
  10. height: 40px;
  11. text-align: center;
  12. border-bottom: 1px solid darkgray;
  13. background-color: darkcyan;
  14. color: white;
  15. font: 18px/40px Arial;
  16. }
  17. #data {
  18. border-collapse: collapse;
  19. }
  20. #data td {
  21. border: 1px solid black;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="page">
  27. <h1 id="header">List</h1>
  28. <h2>Buy groceries</h2>
  29. <ul>
  30. <li id="one" class="hot"><em>fresh</em>&nbsp;<em>figs</em></li>
  31. <li id="two" class="hot">pine nuts</li>
  32. <li id="three" class="hot"><span>honey</span></li>
  33. <li id="four">balsamic vinegar</li>
  34. </ul>
  35. <table id="data">
  36. <tr>
  37. <td>Item 1</td>
  38. <td>Item 2</td>
  39. <td>Item 3</td>
  40. <td>Item 4</td>
  41. <td>Item 5</td>
  42. </tr>
  43. <tr>
  44. <td>Item 1</td>
  45. <td>Item 2</td>
  46. <td>Item 3</td>
  47. <td>Item 4</td>
  48. <td>Item 5</td>
  49. </tr>
  50. <tr>
  51. <td>Item 1</td>
  52. <td>Item 2</td>
  53. <td>Item 3</td>
  54. <td>Item 4</td>
  55. <td>Item 5</td>
  56. </tr>
  57. </table>
  58. <button id="clearBtn">清空表格</button>
  59. </div>
  60. <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
  61. <script>
  62. $(function() {
  63. $('#page li:gt(0)').on('click', function(evt) {
  64. $(evt.target).remove();
  65. });
  66. $('#page li:even').css({
  67. 'background-color': 'coral',
  68. 'font-size': '36px'
  69. });
  70. $('#page li:odd').css('background-color', 'pink');
  71. $('#clearBtn').on('click', function() {
  72. $('#data').empty();
  73. });
  74. });
  75. </script>
  76. </body>
  77. </html>