繁体   English   中英

从TR获取TD值

[英]Getting TD value from TR

我是Java语言的新手,我很难从<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);
});

我需要第一个<td>data-id

您可以尝试使用getAttribute

document.getElementsByTagName("td")[0].getAttribute("data-id");

或使用jQuery,您可以将代码修改为

$("#lista_ativo").delegate("tbody tr", "click", function() {
    var idbcorporativo = $(this).children().attr("data-id");
    console.log(idbcorporativo);
});

这是小提琴例子

您需要从tr转到th。

然后引用以0开头的第一个孩子。

  var idbcorporativo = $(this).children()[0].attr("data-id");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM