html 如何获取表格中所选行的一行数据,并赋值到对应的TEXT里面?
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function cc(){
var bb=document.getElementById("abc").getElementsByTagName("td");
for(var i=0;i<bb.length;i++){
bb[i].onclick= function(){
document.form1.txt.value=this.innerText;
}
}
}
</script>
</head>
<body>
点下单元格看看
<table width="600" border="1" cellspacing="0" cellpadding="0" id="abc">
<tr>
<td height="20" align="center">11</td>
<td align="center">22</td>
<td align="center">33</td>
</tr>
<tr>
<td height="20" align="center">wer</td>
<td align="center">werf</td>
<td align="center">sdf</td>
</tr>
<tr>
<td height="20" align="center">sdf</td>
<td align="center">wer</td>
<td align="center">ewr</td>
</tr>
<tr>
<td height="20" align="center">sdf</td>
<td align="center">sdf</td>
<td align="center">sdf</td>
</tr>
</table>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="txt" id="txt" />
</form>
<p> </p>
<p><br />
</p>
<script language="javascript">
cc();
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function cc(){
var bb=document.getElementById("abc").getElementsByTagName("td");
for(var i=0;i<bb.length;i++){
bb[i].onclick= function(){
document.form1.txt.value=this.innerText;
}
}
}
</script>
</head>
<body>
点下单元格看看
<table width="600" border="1" cellspacing="0" cellpadding="0" id="abc">
<tr>
<td height="20" align="center">11</td>
<td align="center">22</td>
<td align="center">33</td>
</tr>
<tr>
<td height="20" align="center">wer</td>
<td align="center">werf</td>
<td align="center">sdf</td>
</tr>
<tr>
<td height="20" align="center">sdf</td>
<td align="center">wer</td>
<td align="center">ewr</td>
</tr>
<tr>
<td height="20" align="center">sdf</td>
<td align="center">sdf</td>
<td align="center">sdf</td>
</tr>
</table>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="txt" id="txt" />
</form>
<p> </p>
<p><br />
</p>
<script language="javascript">
cc();
</script>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询