我有一个表格是循环出来的、我想设计成当用户点击其中某一个tr时弹出一个层、这个层所显示在页面中的高度、要由tr的值决定、所以我需要获取每个循环出来tr的rowIndex 以方便计算div在屏幕上的位置、我根据网上的教程、现在获取到的rowIndex的值始终为0,请问对于while循环出来的tr难道每一行的rowIndex值都为0么?对于我这种需求还有其他处理方法么?
function popUserDetail(x,y){
var popUp = document.getElementById("popUserDetail");
popUp.style.top="100px";
popUp.style.left="150px";
popUp.style.width="200px";
popUp.style.height="100px";
popUp.style.visibility="visible";
alert(y.rowIndex);
alert(x);
}
while ($records = mysql_fetch_array($rows))
{
$arr = ct($records['uniqueid']);
$fileLastUploadTime = $arr[1];
print '<table id="tb2">
<tr onclick="popUserDetail('.$records["uniqueid"].',this)" onmousemove="hidePopUserDetail()">
<td width="40px">'.st($records['lastT'],$fileLastUploadTime).'</td>
<td width="100px">'.$records['barName'].'</td>
<td width="160px">'.$records['lastLogin'].'</td>
<td width="160px">'.date("Y-m-d H:i:s",$arr[1]).'</td>
<td width="150px">'.$records['endTM'].'</td>
<td width="40px">'.$arr[0].'</td>
<td width="40px">'.$records['version'].'</td>
</tr>
</table>';
}
function popUserDetail(x,y){
var popUp = document.getElementById("popUserDetail");
popUp.style.top="100px";
popUp.style.left="150px";
popUp.style.width="200px";
popUp.style.height="100px";
popUp.style.visibility="visible";
alert(y.rowIndex);
alert(x);
}
while ($records = mysql_fetch_array($rows))
{
$arr = ct($records['uniqueid']);
$fileLastUploadTime = $arr[1];
print '<table id="tb2">
<tr onclick="popUserDetail('.$records["uniqueid"].',this)" onmousemove="hidePopUserDetail()">
<td width="40px">'.st($records['lastT'],$fileLastUploadTime).'</td>
<td width="100px">'.$records['barName'].'</td>
<td width="160px">'.$records['lastLogin'].'</td>
<td width="160px">'.date("Y-m-d H:i:s",$arr[1]).'</td>
<td width="150px">'.$records['endTM'].'</td>
<td width="40px">'.$arr[0].'</td>
<td width="40px">'.$records['version'].'</td>
</tr>
</table>';
}
解决方案 »
- 各位兄弟帮我看看是怎么回事!
- 有关switch的问题
- JS生成年月组合下拉框
- 会自动消失的层
- servlet+ html +javascript的布局,但是公司不让用ajax之类的框架来进行值传递,各位有什么 good ideas 吗?
- 大侠们帮忙看看这段代码,怎么让头一张图片很快闪到第二张
- 请问jquery如果在 $(document).ready()里动态添加内容?
- 急,在线等!100分的标题栏按钮问题
- 抢分的机会,兄弟上吧
- 如何用一个Button或连接实现鼠标右键"save picture as"的功能?
- 得到图片的新顺序并写在新数组里,用JS如何实现呢?有源码
- 关于JS失去焦点和点击事件的问题
不是说tr每次被创建都会生成一个rowIndex的嘛、我不是很理解、如果我要获取鼠标选择的当前行有其他方法可以处理么?
<!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=utf-8" />
<title>无标题文档</title>
</head><body>
<!--表1具有一行二列-->
<table width="500" border="1">
<tr>
<td> </td>
<td> </td>
</tr>
</table><!--表2具有二行二列-->
<table width="500" border="1">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table><script type="text/javascript">
//获取所有的tr节点,两个表格加起来一共有3行
var obj = document.getElementsByTagName('tr');//遍历输出各行的rowIndex
for (var i = 0; i < obj.length; i ++) alert(obj[i].rowIndex);
/*运行结果:
0 -- 第一个表格的第0行
0 -- 第二个表格的第0行
1 -- 第二个表格的第1行
*/
</script>
</body>
</html>