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

猜你喜欢

转载自blog.csdn.net/qq_43746757/article/details/86303246