当前位置: 代码迷 >> JavaScript >> 请问怎么得到表格的行号和列号
  详细解决方案

请问怎么得到表格的行号和列号

热度:83   发布时间:2012-03-19 22:03:05.0
请教如何得到表格的行号和列号
<script   language=javascript>
        <!--  
    function   m(obj){
var   k   =   document.getElementById( "tab ");
for   (var   i   =   0;   i   <   k.getElementsByTagName( "tr ").length;i++){
if   (k.getElementsByTagName( "tr ")[i]   ==   obj){
alert( "第 "   +   (i   +   1)   +   "行 ");
break;
}
}
}
     
            //-->
    </script>

------解决方案--------------------
调试过了
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "读table的值.aspx.cs " Inherits= "读table的值 " %>

<!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 runat= "server ">
<title> Untitled Page </title>
<script type= "text/javascript ">
function Getvalues()
{
// debugger
var TableName = document.getElementById( "text ");
document.getElementById( "row ").innerText= "行号: "+(event.srcElement.parentElement.rowIndex+1);
document.getElementById( "column ").innerText= "列号: "+(event.srcElement.cellIndex+1);
document.getElementById( "values ").innerText= "数值: "+(event.srcElement.innerText);
}

</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<table id= "text " border= "1 " style= "border-collapse:collapse " width= "400px " height= "400px " onmousemove= "Getvalues() "> <tr> <td> 1行1列
</td> <td> 1行2列 </td> </tr>
<tr> <td> 2行1列 </td> <td> 2行2列 </td> </tr>
</table>
<input id= "row " type= "text " />
<input id= "column " type= "text " />
<input id= "values " type= "text " />
</div>
</form>
</body>
</html>
  相关解决方案