点中表格table的一行选中当前行的多选框,用js或者jquery怎么实现?在线等,急!!
<table><thead><tr><td>选择</td><td>姓名</td><td>日期</td><td>金额</td><td>说明</td></tr></thead...
<table >
<thead>
<tr>
<td>选择</td>
<td>姓名</td>
<td>日期</td>
<td>金额</td>
<td>说明</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-01-02</td>
<td>12.35</td>
<td>A股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-02-02</td>
<td>122.35</td>
<td>B股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-03-02</td>
<td>132.35</td>
<td>现金</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-04-02</td>
<td>142.35</td>
<td>港股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-05-02</td>
<td>152.35</td>
<td>保险</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-06-02</td>
<td>162.35</td>
<td>基金</td>
</tr>
</tbody>
</table> 展开
<thead>
<tr>
<td>选择</td>
<td>姓名</td>
<td>日期</td>
<td>金额</td>
<td>说明</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-01-02</td>
<td>12.35</td>
<td>A股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-02-02</td>
<td>122.35</td>
<td>B股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-03-02</td>
<td>132.35</td>
<td>现金</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-04-02</td>
<td>142.35</td>
<td>港股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-05-02</td>
<td>152.35</td>
<td>保险</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-06-02</td>
<td>162.35</td>
<td>基金</td>
</tr>
</tbody>
</table> 展开
展开全部
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function(){
$("table tr").click(function(){
var input = $(this).find("input[type=checkbox]");//获取checkbox
//判断当前checkbox是否为选中状态
if(input.attr("checked")){
input.attr("checked",false);
}else{
input.attr("checked",true);
}
})
})
</script>
<table >
<thead>
<tr>
<td>选择</td>
<td>姓名</td>
<td>日期</td>
<td>金额</td>
<td>说明</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-01-02</td>
<td>12.35</td>
<td>A股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-02-02</td>
<td>122.35</td>
<td>B股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-03-02</td>
<td>132.35</td>
<td>现金</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-04-02</td>
<td>142.35</td>
<td>港股</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-05-02</td>
<td>152.35</td>
<td>保险</td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td>张三</td>
<td>2009-06-02</td>
<td>162.35</td>
<td>基金</td>
</tr>
</tbody>
</table>
追问
刚刚试了下,第一次点击可以取消选中,再点击不能再选中了
追答
代码没错,其实就是jquery的版本问题,换上新的代码。
<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function(){
$("table tr").click(function(){
var input = $(this).find("input[type=checkbox]");//获取checkbox
//判断当前checkbox是否为选中状态
if(input.is(":checked")){
input.attr("checked",false);
}else{
input.attr("checked",true);
}
})
})
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询