我試圖根據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