1. 程式人生 > >jquery遍歷表格獲取表格當前行資料

jquery遍歷表格獲取表格當前行資料

                       

jquery程式碼

  $(".myclass").each(function(){        $("#sub",this).click(function(){            //  alert(1)
          alert($(this).parents("tr").html());                  });              });     });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

表格html程式碼

<table border="1">  <tr class="myclass">    <th>Month</th>    <th>Savings</th>  <th><input id="sub" type="submit" ></input></th>  </tr
>
  <tr class="myclass">    <td>January</td>    <td>$100</td>    <th><input id="sub" type="submit" ></input></th>  </tr></table>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

通過$(this)獲取所點選的按鈕,

$(this).parents(“tr”)獲取按鈕所在行,

$(this).parents(“tr”).find(“.”).text()獲取按鈕所在行class為的元素的值。
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述

           

再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智慧的隊伍中來!https://blog.csdn.net/jiangjunshow