<html>
<head>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
</head>
<body>
<table id="thisTable">
<tr>
<td>id</td>
<td name="Myname" onclick="Myclick()">name</td>
<td>sex</td>
</tr>
<tr>
<td>001</td>
<td name="Myname" onclick="Myclick()">Xiaoming</td>
<td>man</td>
</tr>
<tr>
<td>002</td>
<td name="Myname" onclick="Myclick()">Laowang</td>
<td>man</td>
</tr>
<tr>
<td>003</td>
<td name="Myname" onclick="Myclick()">Yan</td>
<td>Felman</td>
</tr>
</table>
</body>
<script>
function Myclick(){
//console.log("click");
var Myname = document.getElementsByName("Myname");
for(var i=0;i<Myname.length;i++){
Myname[i].hidden="true";
}
}
</script>
</html>
換了種寫法
<html>
<head>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
</head>
<body>
<table id="thisTable">
<tr>
<td>id</td>
<td name="Myname" onclick="Myclick()">name</td>
<td>sex</td>
</tr>
<tr>
<td>001</td>
<td name="Myname" onclick="Myclick()">Xiaoming</td>
<td>man</td>
</tr>
<tr>
<td>002</td>
<td name="Myname" onclick="Myclick()">Laowang</td>
<td>man</td>
</tr>
<tr>
<td>003</td>
<td name="Myname" onclick="Myclick()">Yan</td>
<td>Felman</td>
</tr>
</table>
</body>
<script>
$(function(){
//給所有的td綁定事件
$("td").click(function(){
//移除一整行
//$(this).parent().remove();
//移除當前列
$(this).remove();//這裡的$(this)表示觸發該事件的元素,也就是你所點擊的那個td
})
})
</script>
</html>