点击表格某列,显示该列的列数.............
点击表格某列,显示该列的列数,多多指教
------解决方案--------------------lz说的列,不是行 <tr>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> new page </title>
<script>
function a(){
var obj=event.srcElement;
var num=obj.parentNode.childNodes.length;
while(obj.nextSibling!=null){
obj=obj.nextSibling;
num--;
}
alert( "你选种的第 "+num+ "列! ");
}
</script>
</head>
<body>
<table border= "1 " width= "100% " id= "table1 " onclick= "a() ">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
------解决方案--------------------那是我理解错了,刚才试了下,获得当前目标td obj以后可以使用obj.cellIndex+1方法可以获取所在的列数,不用循环