我想限制图像类显示的图像数量。我目前有以下内容:
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
使用jQuery我怎么限制上面说只显示5个带有“lImg”类的图像
干杯, 丹
答案 0 :(得分:2)
$('.lImg').each(function(i){
if(i>4)
$(this).hide();
});
或者只是:
$('.lImg:gt(4)').hide();
答案 1 :(得分:0)
HTML
<img class="lImg show" src="image.jpg" />
<img class="lImg show" src="image.jpg" />
<img class="lImg show" src="image.jpg" />
<img class="lImg show" src="image.jpg" />
<img class="lImg show" src="image.jpg" />
<img class="lImg" src="image.jpg" />
<img class="lImg" src="image.jpg" />
CSS
.lImg {display:none;}
.lImg.show {display:block;}