获取table表格行号列号
<html> <head> <title> New Document </title> </head> <body> <table > <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr> <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr> <tr><td>aaa</td><td>aaa</td><td>aaa</td><td>aaa</td></tr> </table> <script language="javascript"> <!-- function clickHandler(id){ var t=document.getElementById(id).getElementsByTagName("td"); var len=t.length; for(var i=0;i<len;i++){ t[i].style.cursor="hand"; if(document.addEventListener) { t[i].addEventListener("click",function(e){ e=e.target; alert("行号:"+e.parentNode.rowIndex+"\n"+"列号:"+e.cellIndex); }); } else { t[i].attachEvent("onclick",function(){ var e=event.srcElement; alert("行号:"+e.parentNode.rowIndex+"\n"+"列号:"+e.cellIndex); }); } } } clickHandler("t"); //--> </script> </body> </html>
相关推荐
行吟阁 2020-08-09
表格的现在还是较为常用的一种标签,但不是用来布局,常见处理、显示表格式数据。在HTML网页中,要想创建表格,就需要使用表格相关的标签。<table> <tr> <td>单元格内的文字</td> ...
gufudhn 2020-08-09
玫瑰小妖 2020-06-07
lyg0 2020-05-28
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
swiftwwj 2020-07-05
pythonclass 2020-06-25
nercon 2020-06-14
pythonclass 2020-06-03
huzijia 2020-05-08
行吟阁 2020-05-11
黎豆子 2020-05-11
玫瑰小妖 2020-05-11
HSdiana 2020-05-10
黎豆子 2020-05-08