我对此有一些影响:
<table>
<tr>
<td></td>
<td></td>
<td>
<table>
<tr>
<td><a href="#" class="fav">click me</a></td>
</tr>
</table>
</td>
</tr>
...
</table>
我在jquery中为类别为“ fav”的锚标记单击事件:
$(".fav").click(function(){
var parentRow = $(this).closest('tr');
});
这给了tr
我第二个表(内的表td
)的引用。我想tr
在初始表中重新获得对的引用。图中的高亮显示了我有参考的地方。箭头显示了我想获得参考的位置。
页面上还有很多其他表格。
您可以使用.parents(选择器)函数:
$(".fav").click(function(){
var parentRow = $(this).parents("tr:eq(1)");
// or $(this).parents("tr").eq(1);
// or $($(this).parents("tr")[1]);
// or $($(this).parents("tr").get(1));
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句