进阶题,简单题:
如何在 jQuery 中执行以下操作(隐藏除 之外的所有内容$(this)
)?
$("table tr").click(function() {
$("table tr:not(" + $(this) + ")").hide();
// $(this) is only to illustrate my problem
$("table tr").show();
});
进阶题,简单题:
如何在 jQuery 中执行以下操作(隐藏除 之外的所有内容$(this)
)?
$("table tr").click(function() {
$("table tr:not(" + $(this) + ")").hide();
// $(this) is only to illustrate my problem
$("table tr").show();
});
$(this).siblings().hide();
$("table.tr").not(this).hide();
顺便说一句,我认为您的意思是$("table tr")
(用空格而不是点)。
您拥有它的方式是,它选择每个具有类tr
(例如,<table class="tr">
)的表,这可能不是您想要的。
有关详细信息,请参阅文档。
如果你想将 not() 与其他一些选择器结合起来,你可以使用 add():
$('a').click(function(e){
$('a').not(this).add('#someID, .someClass, #someOtherID').animate({'opacity':0}, 800);
});
这将淡出所有其他链接,但点击的链接,另外淡出一些选定的 id 和类。
我认为一个解决方案可以是这样的:
$("table.tr").click(function() {
$("table.tr:not(" + $(this).attr("id") + "").hide(); // $(this) is only to illustrate my problem
$(this).show();
})
--编辑评论:
$("table.tr").click(function() {
$("table.tr:not(#" + $(this).attr("id") + ")").hide(); // $(this) is only to illustrate my problem
$(this).show();
})