Latest web development tutorials

HTML DOM tr rowIndex 屬性

tr 對象參考手冊 tr對象

定義和用法

rowIndex屬性返回某一行( rows )在表格的行集合中的位置(row index)。

語法

返回rowIndex 屬性:

trObject.rowIndex

提示: rowIndex屬性沒有默認值。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持rowIndex 屬性


實例

實例

下面的例子返回了某一行在表格中的位置:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(x){
    alert("Row index is: " + x.rowIndex);
}
</script>
</head>
<body>

<table border="1">
    <tr onclick="displayResult(this)">
        <td>单击显示行下标</td>
    </tr>
    <tr onclick="displayResult(this)">
    <td>单击显示行下标</td>
    </tr>
    <tr onclick="displayResult(this)">
    <td>单击显示行下标</td>
    </tr>
</table>

</body>
</html>

嘗試一下»


tr 對象參考手冊 tr對象