jquery实现表格中点击相应行变色功能

来源:互联网 发布:义乌聚宝软件 编辑:程序博客网 时间:2024/05/16 15:40

对于一个表格,为了使我们选中的项更容易区分,需要为选中项添加高亮,同时也需要,将其他项的高亮形式去除。类似于:

复制代码
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>    <meta charset="utf-8" />    <title></title>    <link href="css/style.css" rel="stylesheet" type="text/css" />    <script src="jquery-1.3.2.min.js"></script>    <script>        $(function () {            $('tbody>tr').click(function () {                $(this).addClass('selected')      //为选中项添加高亮                .siblings().removeClass('selected')//去除其他项的高亮形式                .end();            });        });     </script></head><body>    <table>        <thead>            <tr><th>姓名</th><th>性别</th><th>暂住地</th></tr>        </thead>        <tbody>            <tr><td>张三</td><td></td><td>浙江宁波</td></tr>            <tr><td>张三</td><td></td><td>浙江宁波</td></tr>            <tr><td>张三</td><td></td><td>浙江宁波</td></tr>            <tr><td>张三</td><td></td><td>浙江宁波</td></tr>            <tr><td>张三</td><td></td><td>浙江宁波</td></tr>        </tbody>    </table></body></html>

1 0