<table border=1>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
</table>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
<tr><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td><td onclick=alert("Cell:"+this.cellIndex);alert("Row:"+this.parentElement.rowIndex)>123123</td></tr>
</table>
function get(obj){
alert("Cell:"+obj.cellIndex+"\nRow:"+obj.parentElement.rowIndex)
}
</script>
<table border=1>
<tr><td onclick=get(this)>123123</td><td onclick=get(this)>123123</td></tr>
<tr><td onclick=get(this)>123123</td><td onclick=get(this)>123123</td></tr>
<tr><td onclick=get(this)>123123</td><td onclick=get(this)>123123</td></tr>
</table>
<table border=1 onclick="getCell()">
<tr>
<td>row:0 col:0</td><td>row:0 col:1</td></tr>
<td>row:1 col:0</td><td>row:1 col:1</td></tr>
<td>row:2 col:0</td><td>row:2 col:1</td></tr>
</table>
<script language="JavaScript">
function getCell(){
var e=event.srcElement;
if(e.tagName=="TD"){
alert("Row:" + e.parentElement.rowIndex + " Col:" + e.cellIndex);
}
}
</script>
我想应该可以实现,自己来得到所在表格的位置的方法的吧,而不是通过传递参数。
document.onclick=function(){
if(event.srcElement.tagName=="TD")
alert("Cell:"+event.srcElement.cellIndex+"\nRow:"+event.srcElement.parentElement.rowIndex)
}
</script>
<table border=1>
<tr><td>123123</td><td>123123</td></tr>
<tr><td>123123</td><td>123123</td></tr>
<tr><td>123123</td><td>123123</td></tr>
</table>
td{qswh:expression(this.innerText='r='+this.parentElement.rowIndex+' ;l='+this.cellIndex)}
</style>
<TABLE id="tb1" border>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
</table>
<script>
var thetd=document.all.tags("TD")
for(i=0;i<thetd.length;i++)
thetd[i].innerHTML="Cell:"+thetd[i].cellIndex+"<br>Row:"+thetd[i].parentElement.rowIndex
</script>