<!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>
点下单元格看看
11 | 22 | 33 |
wer | werf | sdf |
sdf | wer | ewr |
sdf | sdf | sdf |