<html>
<head>
<title>jQ 全选</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script>
$(function(){
$("input[type=checkbox]:eq(0)").change(function(){ //获取索引为0的input
var cstate=$(this).attr("checked"); //获取当前input的状态
$("input[type=checkbox]:not(0)").attr("checked",cstate); //使除了索引为0的checked状态和this保持一致
})
})
<table>
<tr>
<td><input type="checkbox"/>全选</td>
<td> 用户名</td>
<td> 密码</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td> 哈哈</td>
<td> 123</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td> 嘿嘿</td>
<td> 321</td>
</tr>
</table>
</body>
</html>
<head>
<title>jQ 全选</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script>
$(function(){
$("input[type=checkbox]:eq(0)").change(function(){ //获取索引为0的input
var cstate=$(this).attr("checked"); //获取当前input的状态
$("input[type=checkbox]:not(0)").attr("checked",cstate); //使除了索引为0的checked状态和this保持一致
})
})
</script>
</head>
<table>
<tr>
<td><input type="checkbox"/>全选</td>
<td> 用户名</td>
<td> 密码</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td> 哈哈</td>
<td> 123</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td> 嘿嘿</td>
<td> 321</td>
</tr>
</table>
</body>
</html>