| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <!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>
- <tbody>
- <tr>
- <th>姓名</th>
- <th>年龄</th>
- <th>性别</th>
- <th>身高</th>
- <th>体重</th>
- </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>
- <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: Write Less Do More -->
- <!-- 加载本地的jQuery文件适合开发和测试时使用 -->
- <script src="js/jquery.min.js"></script>
- <!-- 下面的方式适合商业项目通过CDN服务器来加速获取jQuery的JS文件 -->
- <!-- <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> -->
- <script>
- // JavaScript Object Notation == JSON
- var stu = {
- 'id': 1001,
- 'name': '骆昊',
- 'age': 15,
- 'study': function(course) {
- alert(this.name + '正在学习' + course);
- },
- 'watchAv': function() {
- if (this.age >= 18) {
- alert(this.name + '正在观看岛国动作片');
- } else {
- alert(this.name + '只能观看《熊出没》');
- }
- }
- };
- stu.study('Python');
- stu.watchAv();
-
- $(function() {
- $('#hide').on('click', function() {
- // 根据样式表选择器获取元素 获取到的不是原生的JS对象
- // 而是经过jQuery封装过后的对象(有更多的方法方便操作)
- $('#data').fadeOut(2000);
- });
- $('#remove').on('click', function() {
- $('#data tr:gt(0):last-child').remove();
- });
- $('#clear').on('click', function() {
- $('#data tr:gt(0)>td').empty();
- });
- $('#pretty').on('click', function() {
- $('#data tr:gt(0):odd').css({
- 'background-color': '#ccc',
- 'font-size': '36px',
- 'font-weight': 'bolder'
- });
- $('#data tr:gt(0):even').css('background-color', '#abc');
- });
- });
- </script>
- </body>
- </html>
|