[英]How to hide all divs except for one with jQuery? (undefined function error)
[英]How to do this hide all rows except one row in jQuery?
如何使用jQuery隐藏除当前(单击的行)以外的所有行?
当我单击当前当前行以外的特定行时,我想隐藏所有行。
<table>
@foreach (var item in Model)
{
idValue++;
<tr class="tableRow" id="@idValue">
<td class="master" id="@item.Batch_Seq">
<a href= "#" >@(item.Batch_Name)></a>
</td>
<td>
@(item.Present)
</td>
<td>
@(item.Absent)
</td>
<td>
@(item.HalfDay)
</td>
<td>
@(item.Batch_count)
</td>
</tr>
}
</table>
我尝试过这样
$('.tableRow').hide();
$(this).closest('tr:not(.tableRow)').hide();
有人可以帮我吗?
您似乎想要这样:
$('.tableRow').click(function(){
$('.tableRow').hide(); // hide all rows
$(this).show(); // show the clicked one
});
请注意,用户无法注意到该行已隐藏然后显示:在事件处理程序结束之前,屏幕不会重新绘制。
使用.not()选择具有tableRow
类的所有元素,但单击的元素除外( this
)
$('tr.tableRow').click(function() {
$('tr.tableRow').not(this).hide();
});
您可以使用not()隐藏所有非“ this”的内容:
$('table tr.tableRow').click(function(){
$('table tr').not(this).hide(); // hide everything that isn't "this"
});
或者您可以使用.siblings()来隐藏所单击行的同级对象
$('table tr').click(function(){
$(this).siblings().hide(); // hide the siblings of the clicked row
});
工作示例: http : //jsfiddle.net/ouadie/U7eUR/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.