当前位置: 首页 > 工具软件 > jsdt-jquery > 使用案例 >

jQuery获取选中TD的值

羊舌高峰
2023-12-01
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>jQuery遍历表格</title>

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
/*<![CDATA[*/
google.load("jquery","1");
/*]]>*/
</script>

</head>
<style>

tr {
	text-align: center;
	bgcolor: ##EAEAEA;
} 

td {
	font-size: 12px; 
	text-decoration: none;
	color: #355f72;
	bgcolor: #FFFFFF;
} 
</style>


<script language="javascript">

$(document).ready(function() {
	$("table td").click(function()	{
		var a = $(this).text();
		alert(a);

	});
});


</script>

<body>
<table width="800" border="1" cellpadding="5" cellspacing="1" bgcolor="#EAEAEA">
	<tr>
		<th>标题1</th>
		<th>标题2</th>
		<th>标题3</th>
		<th>标题4</th>
	</tr>
	<tr>
		<td>数值11</td>
		<td>数值12</td>
		<td>数值13</td>
		<td>数值14</td>
	</tr>
	<tr>
		<td>数值21</td>
		<td>数值22</td>
		<td>数值23</td>
		<td>数值24</td>
	</tr>
	<tr>
		<td>数值31</td>
		<td>数值32</td>
		<td>数值33</td>
		<td>数值34</td>
	</tr>
</table>
</body>
</html>

 类似资料: