使用jQuery最近的()函数吗? [英] Using the Jquery closest() function?
本文介绍了使用jQuery最近的()函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的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
-我尝试使用父级和其他替代方法,但都无法使它起作用:(>
为这个愚蠢的问题表示歉意,类似于我以前遇到的一个问题.只是想知道,什么是最好的解决方案?
谢谢!
解决方案
尝试使用:
$('.show_r3c').click(function() {
$(this).parent('tr').next('tr.r3c').toggle();
return false;
});
Here's my HTML:
<tr>
<td class="show_r3c">click here</td>
</tr>
<tr class="r3c">
<td>This is what I'd like to display</td>
</tr>
And I have currently got this JQuery code,
$(document).ready(function(){
$(".r3c").hide();
$('.show_r3c').click(function() {
$(this).closest('.r3c').toggle();
return false;
});
});
For some reason the closest()
function isn't working, and it won't toggle the table row .r3c
- I've tried using parent and other alternatives but can't get it working either :(
Apologies for the silly question, and something similar to a problem I've had before. Just wondering, What's the best solution for this ?
Thanks!
解决方案
Try with:
$('.show_r3c').click(function() {
$(this).parent('tr').next('tr.r3c').toggle();
return false;
});
这篇关于使用jQuery最近的()函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文