我遇到了问题;我试图让所有其他DIV
关闭并切换。
我自己试图修理它,但我卡住了。我希望有人可以指出我做错了什么。
它没有在not(...)
:
$(document).ready(function() {
$('.extralink').click(function() {
$(this).closest('tr').next('tr.extra').toggle();
$(this).not($(this).closest('tr').next('tr.extra')).hide;
});
}
html
<table class="avs" border="1" width="384px">
<tr class="avs">
<th>Avatar name</th>
<th >Position</th>
</tr>
<tr class='avs'>
<td>
<a class='extralink' href="#"></a>
</td>
<td></td>
</tr>
<tr class='extra'>
<td colspan='2' >
<div>
<div>info</div>
<div>image</div>
</div>
</td>
</tr>
<tr class='avs'>
<td>
<a class='extralink' href="#"></a>
</td>
<td></td>
</tr>
<tr class='extra'>
<td colspan='2' >
<div>
<div>info</div>
<div>image</div>
</div>
</td>
</tr>
</table>
答案 0 :(得分:4)
你错过了隐藏功能上的(),需要说你实际上是在调用它!
$(this).not($(this).closest('tr').next('tr.extra')).hide();
答案 1 :(得分:0)
如果您展示更多HTML,它会有所帮助。但这里有一些指导可以帮助你
$(document).ready(function() {
$('.extralink').click(function() {
// should cache the tr
$(this).closest('tr').next('tr.extra').toggle();
$(this).not($(this).closest('tr').next('tr.extra')).hide; //<--missing ()
// usually not() isn't used with this - as anything with this is usually used inside not() to filter out
});
}
所以这样的事情看起来会更好
$(document).ready(function() {
$('.extralink').click(function() {
var $tr = $(this).closest('tr').next('tr.extra');
$tr.toggle();
$('tr.extra').not($tr).hide(); // <-- I'm guessing this is correct
// since it's these tr's you are looking for to toggle
});
}