[英]How to check value of td element inside parent tr element from another child td element
我正在使用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>
有人可以幫我嗎? 提前致謝。 =)
單擊按鈕時,您可以要求最接近的 tr
,然后找到特定的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.