我试图根据nth-child或基于计数的选择器做出一些隐藏显示项。 如果我点击第一行的第一个项目,那么第二行的第一个项目应该显示,并且该行中的其他项目应该隐藏。请帮助简化代码。基于子nth的子类隐藏显示在多行中
$(document).ready(function(){
$(".subrow1 .item-a a:nth-child(1)").click(function(){
$(".subrow2 .idgroupsub:nth-child(1)").show();
$(".subrow2 .idgroupsub:nth-child(2)").hide();
$(".subrow2 .idgroupsub:nth-child(3)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
$(".subrow1 .item-a a:nth-child(2)").click(function(){
$(".subrow2 .idgroupsub:nth-child(2)").show();
$(".subrow2 .idgroupsub:nth-child(1)").hide();
$(".subrow2 .idgroupsub:nth-child(3)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
$(".subrow1 .item-a a:nth-child(3)").click(function(){
$(".subrow2 .idgroupsub:nth-child(3)").show();
$(".subrow2 .idgroupsub:nth-child(1)").hide();
$(".subrow2 .idgroupsub:nth-child(2)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
});
http://jsfiddle.net/Lv5cn8xy/244/
https://api.jquery.com/ index /,https://api.jquery.com/eq/ – CBroe