<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>取td的值</title>
</head>
<body>
<table border="1">
<tr>
<%for(int j=0;j<4;j++){ %>
<td>第<%=(j) %>列</td>
<%} %>
</tr>
<%for(int i=0;i<4;i++){ %>
<tr>
<td><input type="checkbox"></td>
<%for(int j=0;j<3;j++){ %>
<td>第<%=i %>行,第<%=(j+1) %>列</td>
<%} %>
</tr>
<%} %>
</table>
<button id="getTdValue">取td的值</button>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<script type="text/javascript">
$(function(){
$("#getTdValue").click(function(){
// 找到选中的复选框
var $check = $("table").find(":checkbox").filter(":checked");
// 找到选中的复选框所在的行
var $tr = $check.eq(0).parent().parent();
// 找到此行中的某个td
// alert($tr.html());
var $td = $tr.find("td").eq(2).text();
alert($td);
});
});
</script>
</body>
</html>
取得选中复选框同一行的某个td中的值
最新推荐文章于 2022-04-03 15:43:54 发布