怎么样能实现鼠标单击取到table中的某行ID?
如下代码:从数据库中提出数据填充到table中,但是现在有一个问题:怎么样能取到某行的ID?
<table border=1 width= "1200 ">
<tr> <td> ÐòºÅ </td> <td> É豸״̬ </td> <td> µÇ¼Ç±í±àºÅ </td> <td> É豸²úȨµ¥Î» </td> <td> É豸Àà±ð </td> <td> É豸Ãû³Æ </td> <td> ×¢²áµÇ¼Ç»ú¹¹ </td> <td> ×¢²áµÇ¼ÇÈÕÆÚ </td> <td> É豸ע²á´úÂë </td> <td> ×¢²áµÇ¼ÇÈËÔ± </td> <td> ¸üÐÂÈÕÆÚ </td> <td> µ¥Î»ÄÚ²¿±àºÅ </td> <td> ³§³µÅÆÕÕ±àºÅ </td> <td> ³§³µÅÆÕÕ±àºÅ </td> <td> ³§³µÅÆÕÕ±àºÅ </td> </tr>
<?
//Ñ­»·
for($i=0;$i <$ar;$i++)
{
echo " <tr> " ;
echo " <td> ";
echo mysql_result($rst1,$i, 'id ');
echo " </td> ";
echo " <td> ";
echo mysql_result($rst1,$i, 'bt ');
echo " </td> ";
echo " <td> ";
echo mysql_result($rst1,$i, 'fbsj ');
echo " </td> ";
?>
</tr>
<?}?>
</table>
[解决办法]
可以加一个input,类型为hidden
[解决办法]
用js取得table的某一行,再得到某个单元格中的内容
[解决办法]
table加个runat= "server " 和 ID
this.Table1.Rows[0].Cells[1] 代表第1行第二个td
[解决办法]
<html>
<head>
<script language = "javascript ">
function aa()
{
for(i=0;i <document.f1.cb.length;i++)
{
if(document.f1.cb[i].checked == true)
{
alert(document.f1.cb[i].parentElement.parentElement.parentElement.rows(i).innerText);
var a = document.f1.cb[i].parentElement.parentElement.parentElement.rows(i).cells.length;
alert(a);
}
}
}
</script>
</head>
<body>
<form name = "f1 ">
<table name = "a ">
<tr>
<td> <input type = "checkbox " name = cb>
</td>
<td> 1
</td>
<td> 11
</td>
</tr>
<tr>
<td> <input type = "checkbox " name = cb>
</td>
<td> 2
</td>
<td> 2222
</td>
<td> 2233333
</td>
<td> 224444444
</td>
</tr>
<tr>
<td> <input type = "checkbox " name = cb>
</td>
<td> 3
</td>
<td> 33
</td>
</tr>
<tr>
<td>
<input type = "button " onclick = "aa() ">
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>