页面上有很多个表格,想做一个通用效果,选中表格的一行,就会选中该行的复选框
<!DOCTYPE html>
<html>
<body>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
</script>
</head>
<script type="text/javascript">
$(document).ready(function()
{
$("table.tp tr").click(function()
{
//实现方法
})
})
</script>
<div>
<table id="tab1" class="tp" border="1" width="300">
<tr>
<td><input type="checkbox"></td>
<td>123</td>
<td>321</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>456</td>
<td>654</td>
</tr>
</table>
</div>
<p>
</p>
<div>
<table id="tab2" class="tp" border="1" with="300">
<tr>
<td><input type="checkbox"></td>
<td>111</td>
<td>222</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>789</td>
<td>999</td>
</tr>
</table>
</div>
</body>
</html>
代码
$(document).ready(function()
{
$("tr").click(function()
{
var chk = $(this).find(':checkbox');
chk.prop('checked', ! chk.prop('checked'));
})
})