特别感谢:
枫叶红(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>