给他加一个行了<table id="table1" activeRow="">
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
</table><input type="button" onclick="alert(table1.activeRow.rowIndex);" value="看看activeRow">
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
<tr onclick="table1.activeRow=this;">
<td>adsf</td>
</tr>
</table><input type="button" onclick="alert(table1.activeRow.rowIndex);" value="看看activeRow">
//<![CDATA[
document.onclick=function(){
alert(document.activeElement.innerHTML);
}
//]]>
</script>
</head> <body id="www.never-online.net">
<table id="table1" border='1'>
<tr>
<td>adsf</td>
</tr>
<tr>
<td>adsf</td>
</tr>
<tr>
<td>adsf</td>
</tr>
</table>
以前写的一段代码,贴一下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title>
<script language=javascript>
var selectedTr=null; function c1(obj){
obj.style.background='#FFFFFF'; //把点到的那一行变希望的颜色;
if(selectedTr!=null) selectedTr.style.backgroundColor="";
if(selectedTr==obj) selectedTr=null;//加上此句,以控制点击变白,再点击反灰
else selectedTr=obj;
}</script>
</head> <body>
单击选中Tr,高亮显示,再单击取消选选中。<input type=button value="选中的是哪一行?" onclick="alert(selectedTr?selectedTr.outerHTML:'没有选中行');">
<table width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor="#cccccc">
<tr onclick="c1(this);">
<td >1 </td>
</tr>
<tr onclick="c1(this);">
<td >2 </td>
</tr>
<tr onclick="c1(this);">
<td >3 </td>
</tr>
</table>
</body>
</html>