如何使用javascript/jquery循环表?

Yiy*_*ang 0 javascript jquery traversal

我有一个像下面的代码块

<tbody class="society_list">
    <tr>
        <td>1</td>
        <td>Dummy</td>
        <td>Dummy</td>
        <td id="lol0">UPDATE THIS</td>
    </tr>
    <tr>
        .....
    </tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)

我想要做的是遍历整个表,找到带有id的td,获取该id的值,然后更新内部的html.我现在有什么(对不起,我很新,我仍然不知道该怎么做......)

function update(){
  var trs = document.querySelectorAll('.society_list tr');
  for(i=0;i<trs.length-1;i++){
    trs[i].find('td').each(function(){
      //I know I need to do something here but what's that.. 
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

Dhi*_*raj 6

使用has属性选择器迭代具有id属性的tds .

$('.society_list tr td[id]').each(function(){
  var tdID = $(this).attr('id'); // <--- getting the ID here
  var result = doSomeMagicWithId(tdID); // <--- doing something
  $(this).html(result);  // <---- updating the HTML inside the td
});
Run Code Online (Sandbox Code Playgroud)