日期:2014-05-16 浏览次数:20351 次
<table>
<tr>
<td>1</td>
<td>aaa</td>
<td>xxx</td>
<td><button class="btn">修改</button></td>
</tr>
<tr>
<td>3</td>
<td>bbb</td>
<td>xxxx</td>
<td><button class="btn">修改</button></td>
</tr>
<tr>
<td>7</td>
<td>ccc</td>
<td>xxx</td>
<td><button class="btn">修改</button></td>
</tr>
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(function(){
$(".btn").click(function(){
var id = $(this).parents("tr").children("td:nth-child(1)").text();
alert(id)
})
})
</script>
$(".btn").click(function () {
alert($(this).parents("tr").children("td:nth-child(1)").text()+"--child");
alert($(this).parents("tr").children("td").first().text()+"--first");
});
<!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>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(function(){
$("table tr").find('td:last').click(function(){
var id = $(this).parents("tr").find('td:first').text();
alert(id)
})
})
</script>
</head>
<body>
<table>
<tr>
<td>1</td>
<td>aaa</td>
<td>xxx</td>
<td>修改</td>
</tr>
<tr>
<td>3</td>
<td>bbb</td>
<td>xxxx</td>
<td>修改</td>
</tr>
<tr>
&