发新话题
打印

Jquery 隐藏列

本主题由 bottle 于 2007-12-10 22:41 加入精华

Jquery 隐藏列


特别感谢:
  枫叶红(QQ:84973381) 路上行人(QQ:357668480)
复制内容到剪贴板
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery 隐藏列</title>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
        var tb = $("#MyTable tbody");
        var tr = tb.children();   // 行集合
        var th = tb.children().eq(0).children(); // 第一行第一列集合
        trLength = tr.size(); // 行数
        thLength = th.size(); // 列数
        th.each(function(){  // 邦定每一个th 的click 事件
                $(this).click(function(){
                        var thIndex = th.index($(this).get(0)); // 取得当前对象的索引
                        for(i=0; i<trLength; i++){
                                tb.children().eq(i).children().eq(thIndex).hide(); // 隐藏列
                        }
                });
        });
});

</script>
</head>

<body>
<table id="MyTable" width="200" border="1">
  <tr>
    <th>1</th>
    <th>2</th>
    <th>3</th>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
</table>

</body>
</html>
空间出租:P4 3.0+1G+RIAD 1 160G+PHP+IIS+MYSQL+MDaemon

QQ:126682182
Email:hhyisw@163.com
Home:http://www.stksky.com

TOP

发新话题