【发布时间】:2018-04-23 09:06:53
【问题描述】:
我有一张桌子。每行都有一个 ID。
我可以通过仅使用其 ID(不点击)而不使用循环来获取任何行的索引吗?
我的 HTML 如下所示:
<table id="tabId">
<tr id="a">
<td>ss</td>
<td>ss</td>
</tr>
<tr id="b">
<td>kk</td>
<td>kk</td>
</tr>
我试过了:
var row_number = document.getElementById('a').rowIndex;
但它不起作用;我收到一个error message 说:
[ts] 类型“HTMLElement”上不存在属性“rowIndex”。
【问题讨论】:
-
这是一个property and not a method ->
document.getElementById(a).rowIndex -
它不是重复的。已经读过那篇文章了。
-
@user2243952 这里是answer。
this和你通过 id 得到的一样。 -
不,该解决方案需要单击该行。我只需要使用 id 的索引
-
The property 'value' does not exist on value of type 'HTMLElement' -> 转换为
HTMLTableRowElement
标签: html angular typescript