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