【问题标题】:How to check value of td element inside parent tr element from another child td element如何从另一个子 td 元素检查父 tr 元素内的 td 元素的值
【发布时间】:2017-10-16 17:16:41
【问题描述】:

我正在使用 jQuery 的 DataTables 表格插件。我有 4 列,其中之一包含按钮(编辑和删除)。在使用 JavaScript/jQuery 单击其中一个按钮时,我需要检查另一列(在同一个父 tr 元素中)的值。

<tr role="row" class="odd">
  <td class="sorting_1">0 <!-- I need this number --> </td>
  <td>Exercise 1</td>
  <td>nl</td>
  <td class=" dt-center"> <!-- this element conatains the buttons --> </td>
</tr>

有人可以帮帮我吗?提前致谢。 =)

【问题讨论】:

    标签: javascript jquery datatables html-table


    【解决方案1】:

    当您点击按钮时,您可以询问closest tr 然后find 特定的td 并询问其中的text

    $(this).closest("tr").find(".sorting_1").text()

    $('.getvalue').click(function() {
      console.log($(this).closest("tr").find(".sorting_1").text())
    })
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table>
      <tr role="row" class="odd">
        <td class="sorting_1">0 </td>
        <td>Exercise 1</td>
        <td>nl</td>
        <td class=" dt-center"> <button class="getvalue">get value</button></td>
      </tr>
      <tr role="row" class="odd">
        <td class="sorting_1">2</td>
        <td>Exercise 2</td>
        <td>n2</td>
        <td class=" dt-center"> <button class="getvalue">get value</button></td>
      </tr>
    </table>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 2016-10-22
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      相关资源
      最近更新 更多