javascript - 使用 jquery 和 for 循环循环 html 表(不是针对每个)

标签 javascript jquery html

我有一个 HTML 表格

 <table id="mytab">
  <thead>
    <th>col1</th>
    <th>col2</th>
  </thead>
  <tbody>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
     <td>11</td>
     <td>22</td>
  </tbody>
 </table>

我正在编写 jquery 函数

  function LoopTable()
  {
      $row = $('#mytab tbody >tr"); //here I have successfully find all the rows.

     //now i want to loop on rows and find each column row
     for (var i=0; i<$rows.length; i++)
     {
         //need something here to find col data

     }

我应该使用什么从行中获取列值

最佳答案

更新代码

$(document).ready(function() {
    var rows = $('#mytab tbody >tr');
    var columns;
    for (var i = 0; i < rows.length; i++) {
        columns = $(rows[i]).find('td');
        for (var j = 0; j < columns.length; j++) {
            console.log($(columns[j]).html());
        }
    }
});

关于javascript - 使用 jquery 和 for 循环循环 html 表(不是针对每个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389290/

相关文章:

javascript - 在javascript中按字符对字符串进行排序

javascript - 切换任何标签,就像 execCommand bold 对 b 所做的那样

jquery - 有人可以解释为什么这在 IE 浏览器中有效吗?

javascript - 使用数据库中的输入填充下拉框,这将导致另一个填充页面

html - CSS - 如何在不使用 "position: absolute"的情况下垂直对齐 div?

javascript - Vuetify 组合框不返回 id 而不是值

javascript - 调用通过 Javascript 加载另一个 HTML 的 Bootstrap Modal

javascript - 如何使用 jQuery 客户端上传图片并将其添加到 div?

jQuery:从类中获取 ID

html - 增加嵌套 (ul ul ul li) 下拉导航列表项的宽度