<head> <script src="jquery-3.3.1.js"></script> <script> $("tr").each(function (i,i1) { //遍历每个tr标签,i为第几个tr标签,也就是第几行,i1是当前标签下的内容 $(this).children("td").each(function (j,j1) { //遍历tr标签下的td标签,j是某行中第几个位置 $(this).click(function () { //$(this).click 获取点击的标签 $(this).val();
//textt=$(this).parent().siblings().eq(1).text(); //
}) }) }) } </script> </head> <body> <table border="1"> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>11</td> <td>22</td> <td>33</td> </tr> </table> </body>
$.each(x,function(k,v){}) //x为要遍历的对象,k为遍历时当前的下标,v为值