我想隐藏每个div块中唯一类名的第一个div。我这样做是因为我有多个轮播,除了第一个div之外,我将每个轮播除外。这对于单个轮播很有用,但是当我引入多个轮播时,它会隐藏除第一个之外的所有div。单转盘jquery,隐藏在div块中的div
原来的代码是:
$("div.hero-featureSwap:not(:first)").css({
"left" : "2000px"
});
,但现在我要显示的每个转盘的第一个“英雄featureSwap”。这是否有黑客入侵?
我想隐藏每个div块中唯一类名的第一个div。我这样做是因为我有多个轮播,除了第一个div之外,我将每个轮播除外。这对于单个轮播很有用,但是当我引入多个轮播时,它会隐藏除第一个之外的所有div。单转盘jquery,隐藏在div块中的div
原来的代码是:
$("div.hero-featureSwap:not(:first)").css({
"left" : "2000px"
});
,但现在我要显示的每个转盘的第一个“英雄featureSwap”。这是否有黑客入侵?
我猜你的结构可能是这样的 -
<div class="carousel">
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
</div>
<div class="carousel">
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
</div>
<div class="carousel">
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
<div class="carousel-child"></div>
</div>
那么这是我会怎样这样做 -
$("div.carousel").each(function(){
$(this).find("div.carousel-child:not(:first)").css({
"left" : "2000px"
});
});
请根据您的结构进行必要的班级名称更改。
使用此代码:
$("div.hero-featureSwap").find('div:gt(0)').hide();
隐藏。要将所有其他的div除了第一个页面,你的代码就好了,或者:
$("div.hero-featureSwap:gt(0)").css({
"left" : "2000px"
});
使用父容器,然后$ .each,然后执行此操作。 – Ohgodwhy
你可能想删除'java'标签:P – mechalynx
除非我们知道html外观如何喜欢,否则答案将会在黑暗中拍摄。您可以发布html,但不是完整的,但只有重要的。 –