我是 Javascript 新手,无法从 <td>
获取值.
下面是一些代码来说明问题:
<div id="lista_ativo">
<table class="tabela-basica" width="100%" cellpadding="0px" cellspacing="0px">
<thead>
<tr>
<th width="35px">ID</th>
<th width="200px">Cliente</th>
<th width="200px">Nome</th>
<th width="35px">OAB</th>
<th width="50px">Estado</th>
</tr>
</thead>
<tbody>
<tr class="{classe_row}">
<td data-id="{andamentos_ativos.clienteid}">{andamentos_ativos.clienteid}</td>
<td>{andamentos_ativos.cliente}</td>
<td>{andamentos_ativos.nome}</td>
<td>{andamentos_ativos.oab} / {andamentos_ativos.oab_uf}</td>
<td>{andamentos_ativos.estados}</td>
</tr>
</tbody>
</table>
</div>
我的 JavaScript:
$("#lista_ativo").delegate("tr", "click", function() {
var idbcorporativo = $(this).attr("data-id");
console.log(idbcorporativo);
});
我需要data-id
从第一个<td>
.
最佳答案
您需要从 tr 转到 th。
然后引用从 0 开始的第一个子元素。
var idbcorporativo = $(this).children()[0].attr("data-id");
关于javascript - 从TR中获取TD值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22328060/