Table的两个属性rowIndex与cellIndex

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 οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
  </tr>
  <tr>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
  </tr>
  <tr>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
    <td οnclick="alert('行:'+(this.parentNode.rowIndex+1)+'列:'+(this.cellIndex+1))">&nbsp;</td>
  </tr>
</table>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值