jquery 如何选中table中的所有checkbox 求高手帮忙解答

如题所述

$("table input[type=checkbox]")
就可以了
然后你就可以执行 $("table input[type=checkbox]").attr("checked",true) 全选之类的了追问

那我如何获取table中checkbox被选中的所对应的行数呢

追答

$("table input:checkbox").each(function(){
if($(this).attr("checked")==true){
alert($("table input:checkbox").index(this))
}
})
希望对你有帮助.

温馨提示:内容为网友见解,仅供参考
第1个回答  2013-05-13
<script type="text/javascript">
function selectall(){
if($("input[name='selectall']").attr("checked")){
$(':checkbox').each(
function() {
$(this).attr("checked", true);
}
);
}else{
$(':checkbox').each(
function() {
if($(this).attr("checked")){
$(this).removeAttr("checked");
}
}
);
}
}
</script>
<body>
<div>
<table bordercolor="#CCCCCC" border="1">
<tr bgcolor="#CCCCCC">
<td><input type="checkbox" name="selectall" onclick="selectall()"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
</tr>
</table>
</div>
第2个回答  2013-05-13
$("table :checkbox")追问

那我如何获取table中checkbox被选中的所对应的行数呢

相似回答