| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- <style>
- #data {
- border-collapse: collapse;
- }
- #data td, #data th {
- width: 120px;
- height: 40px;
- text-align: center;
- border: 1px solid black;
- }
- #buttons {
- margin: 10px 0;
- }
- </style>
- </head>
- <body>
- <table id="data">
- <caption>数据统计表</caption>
- <thead>
- <tr>
- <th>姓名</th>
- <th>年龄</th>
- <th>性别</th>
- <th>身高</th>
- <th>体重</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- <tr>
- <td>Item1</td>
- <td>Item2</td>
- <td>Item3</td>
- <td>Item4</td>
- <td>Item5</td>
- </tr>
- </tbody>
- </table>
- <div id="buttons">
- <button id="pretty">隔行换色</button>
- <button id="clear">清除数据</button>
- <button id="remove">删除一行</button>
- <button id="hide">表格淡出</button>
- </div>
- <!-- 引入jQuery -->
- <script src="js/jquery.min.js"></script>
- <!-- <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> -->
- <script>
- // $('选择器') --> jQuery对象 --> 封装了很多的方法
- $('#pretty').on('click', () => {
- $('#data>tbody>tr:odd').css('background-color', 'lightgray')
- $('#data>tbody>tr:even').css('background-color', 'lightgreen')
- })
- $('#clear').on('click', () => {
- $('#data>tbody>tr>td').empty()
- })
- $('#remove').on('click', () => {
- $('#data>tbody>tr:last-child').remove()
- })
- $('#hide').on('click', () => {
- let title = $('#hide').text()
- if (title == '表格淡出') {
- $('#data').fadeOut(1000, () => {
- $('#hide').text('表格淡入')
- })
- } else {
- $('#data').fadeIn(2000, () => {
- $('#hide').text('表格淡出')
- })
- }
- })
- </script>
- </body>
- </html>
|