JQuery实现双色表格

来源:互联网 发布:php cli 进度条 编辑:程序博客网 时间:2024/04/30 20:39
<!--

        Document     : 双色表格

        Created on : 2008-10-28, 19:23:56

        Author         : Administrator

-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

        <head>

                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

                <title>双色表格</title>

                <script src="jquery.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){    //这个就是传说的ready

                $(".stripe tr").mouseover(function(){    

                                //如果鼠标移到class为stripe的表格的tr上时,执行函数

                                $(this).addClass("over");}).mouseout(function(){

                                //给这行添加class值为over,并且当鼠标一出该行时执行函数

                                $(this).removeClass("over");})    //移除该行的class

                $(".stripe tr:even").addClass("alt");

                                //给class为stripe的表格的偶数行添加class值为alt

});

</script>

<style type="text/css">

th {

                background:#0066FF;

                color:#FFFFFF;

                line-height:20px;

                height:30px;

}

td {

                padding:6px 11px;

                border-bottom:1px solid #95bce2;

                vertical-align:top;

                text-align:center;

}

td * {

                padding:6px 11px;

}

tr.alt td {

                background:#ecf6fc;    /*这行将给所有的tr加上背景色*/

}

tr.over td {

                background:#bcd4ec;    /*这个将是鼠标高亮行的背景色*/

}

</style>

</head>

<body>

<table class="stripe" width="50%" border="0" cellspacing="0" cellpadding="0">



<thead>

    <tr>

        <th>姓名</th>

        <th>年龄</th>

        <th>QQ</th>

        <th>Email</th>

    </tr>

</thead>

<tbody>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

    <tr>

        <td>Jerry</td>

        <td>30</td>

        <td>2551577</td>

        <td>wangjr@stditbase.com</td>

    </tr>

</tbody>

</table>

</body>

</html>

效果如下: