今天在LlinZzi's Blog 上看到关于这两个属性的介绍,感觉挺有趣,并且也比较具有使用价值。
rowIndex用于判断当前单元格所处行的索引(从0开始)
cellIndex用于判断当前单元格所处列的索引(从0开始)
通常我们可以把他们的事件写在TD里,因为rowIndex属性应该是属于<tr>标记,因此在判断rowIndex需要访问父节点,
示例如下:
rowIndex用于判断当前单元格所处行的索引(从0开始)
cellIndex用于判断当前单元格所处列的索引(从0开始)
通常我们可以把他们的事件写在TD里,因为rowIndex属性应该是属于<tr>标记,因此在判断rowIndex需要访问父节点,
示例如下:
<
table
align
="center"
width
="100%"
height
="400"
cellspacing
="1"
border
="1"
bordercolor
="#000000"
bordercolorlight
="#000000"
bordercolordark
="#C0C0C0"
bgcolor
="#C0C0C0"
>
< tr >
< td > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
< tr >
< td onclick ="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))" > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
< tr >
< td > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
</ table >
< tr >
< td > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
< tr >
< td onclick ="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))" > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
< tr >
< td > </ td >
< td > </ td >
< td > </ td >
< td > </ td >
</ tr >
</ table >