jQuery获取TD单元格的值

时间:2018-06-28 08:54:12

标签: jquery

我有以下HTML:

<tr data-uid="2639f8d8-5459-42fb-b51c-b071db6c1541" role="row">
  <td class="" role="gridcell">1</td>
  <td class="" role="gridcell">06/12/2018</td>
  <td class="" role="gridcell">Feeding</td> 
  <td class="" role="gridcell">some long text data</td>

  <td class="k-command-cell" role="gridcell">
  <a role="button" class="k-button k-button-icontext k-grid-ViewDetails" 
  href="#">View Details</a></td>

</tr>

像这样的表中有很多行。...我需要获取在这种情况下为'1'的ID值。我试图获取属性角色值,但没有运气。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我不确定您的问题到底是什么,但是我正在发布一个简单的示例,该示例收集表中的所有ID。

$(function(){
  var ids = $('tr').map(function(){ 
        return $(this).children('td').first().text()
  }).get();
  console.log(ids); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<table>
<tr data-uid="2639f8d8-5459-42fb-b51c-b071db6c1541" role="row">
  <td class="" role="gridcell">1</td>
  <td class="" role="gridcell">06/12/2018</td>
  <td class="" role="gridcell">Feeding</td> 
  <td class="" role="gridcell">some long text data</td>

  <td class="k-command-cell" role="gridcell">
  <a role="button" class="k-button k-button-icontext k-grid-ViewDetails" 
  href="#">View Details</a></td>

</tr>
<tr data-uid="2639f8d8-5459-42fb-b51c-b071db6c1541" role="row">
  <td class="" role="gridcell">2</td>
  <td class="" role="gridcell">07/12/2018</td>
  <td class="" role="gridcell">Feeding 2</td> 
  <td class="" role="gridcell">some long text data ...</td>

  <td class="k-command-cell" role="gridcell">
  <a role="button" class="k-button k-button-icontext k-grid-ViewDetails" 
  href="#">View Details</a></td>

</tr>
</table>