• jQuery实现表格间隔色


    1、新建一个web项目,jQuery;


    2、在WebContent目录下新建script文件夹,将jquery-1.10.1.js复制到script中;


    3、同样,新建TableColor.html;

    TableColor.html:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>表格间隔色</title>
    <script type="text/javascript" src="script/jquery-1.10.1.js"></script>
    <style type="text/css">
       body
       {
         100%;
         height:100%;
         font-size:12px;
       }
       table
       {
         80%;
         height:90%;
       }
       .tr_odd
       {
         background: #EBF2FE;
       }
       .tr_even
       {
         background: #B4CDE6;
       }
       .tab_body
       {
         text-align: center;
       }
    </style>
    <script type="text/javascript">
       $(function(){
    	   $("tr:odd").addClass("tr_odd");
    	   $("tr:even").addClass("tr_even");
       });
    </script>
    </head>
    <body>
       <table>
          <tr style="background: #CCCCCC;text-align: center;">
            <th>学号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>性别</th>
          </tr>
          <tr class="tab_body">
            <td>2013060101</td>
            <td>张华</td>
            <td>23</td>
            <td>男</td>
          </tr>
          <tr class="tab_body">
            <td>2013060102</td>
            <td>赵雪</td>
            <td>24</td>
            <td>女</td>
          </tr>
          <tr class="tab_body">
            <td>2013060103</td>
            <td>孙旭</td>
            <td>21</td>
            <td>男</td>
          </tr>
          <tr class="tab_body">
            <td>2013060104</td>
            <td>李姝</td>
            <td>20</td>
            <td>女</td>
          </tr>
          <tr class="tab_body">
            <td>2013060105</td>
            <td>公孙旭</td>
            <td>22</td>
            <td>男</td>
          </tr>
          <tr class="tab_body">
            <td>2013060106</td>
            <td>李枝花</td>
            <td>24</td>
            <td>女</td>
          </tr>
          <tr class="tab_body">
            <td>2013060107</td>
            <td>魏征</td>
            <td>22</td>
            <td>男</td>
          </tr>
          <tr class="tab_body">
            <td>2013060108</td>
            <td>施礼</td>
            <td>20</td>
            <td>女</td>
          </tr>
          <tr class="tab_body">
            <td>2013060109</td>
            <td>王志</td>
            <td>23</td>
            <td>男</td>
          </tr>
          <tr class="tab_body">
            <td>2013060104</td>
            <td>方小许</td>
            <td>20</td>
            <td>女</td>
          </tr>
       </table>
    </body>
    </html>

    4、运行http://localhost:8080/jQuery/TableColor.html,结果如下图:


  • 相关阅读:
    Java异常处理和设计
    一次qps测试实践
    Alternate Task UVA
    Just Another Problem UVA
    Lattice Point or Not UVA
    Play with Floor and Ceil UVA
    Exploring Pyramids UVALive
    Cheerleaders UVA
    Triangle Counting UVA
    Square Numbers UVA
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315791.html
Copyright © 2020-2023  润新知