jQuery 点击选中单元格,该单元格的整行和整列都被选中!怎么实现了?急急急!!!
1个回答
展开全部
$("td").click(function(){
var me = $(this);
me.closest("table").find("tr,td").css("backgroundColor","");
var tr = me.closest("tr").css("backgroundColor","red");
var table = tr.closest("table");
table.find("tr").find("td")
.eq(me.index("tr>td")).css("backgroundColor","red");
});
追问
不行啊!
追答
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<script>
$(function(){
$("td").click(function(){
var me = $(this);
me.closest("table").find("tr,td").css("backgroundColor","");
var tr = me.closest("tr").css("backgroundColor","red");
var table = tr.closest("table");
table.find("tr").find("td:eq("+me.index()+")").css("backgroundColor","red");
});
});
</script>
</head>
<body>
<table>
<tr>
<td>
232
</td>
<td>
232
</td>
<td>
232
</td>
</tr>
<tr>
<td>
232
</td>
<td>
232
</td>
<td>
232
</td>
</tr>
<tr>
<td>
232
</td>
<td>
232
</td>
<td>
232
</td>
</tr>
</table>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询