这是我的HTML:
<tr>
<td class="show_r3c">click here</td>
</tr>
<tr class="r3c">
<td>This is what I'd like to display</td>
</tr>我现在得到了这个JQuery代码,
$(document).ready(function(){
$(".r3c").hide();
$('.show_r3c').click(function() {
$(this).closest('.r3c').toggle();
return false;
});
});由于某些原因,closest()函数无法工作,并且它不会切换表行.r3c -我已经尝试使用parent和其他替代方法,但也无法使其工作:(
为这个愚蠢的问题道歉,还有一些类似于我以前遇到的问题。只是想知道,对此最好的解决方案是什么?
谢谢!
发布于 2009-08-28 13:40:53
尝试使用:
$('.show_r3c').click(function() {
$(this).parent('tr').next('tr.r3c').toggle();
return false;
});发布于 2009-08-28 13:37:13
closest()查找最接近的父节点,而不是父节点-兄弟节点-子节点。
你想要这样的东西:
$(document).ready(function(){
$(".r3c").hide();
$('.show_r3c').click(function() {
$(this).closest('table').find("tr.r3c").toggle(); return false;
});
});发布于 2009-08-28 13:33:40
也许这会起作用:
$(document).ready(function(){
$(".r3c").hide();
$('.show_r3c').click(function() {
$(this).parent().siblings(":first").toggle();
return false;
});
});https://stackoverflow.com/questions/1346972
复制相似问题