-3
我想限制選擇。比方說,最多三個。我該怎麼做呢?幫助將非常感激。謝謝。用jquery選擇最多10個li物品
$(function(){
var classHighlight = 'highlight';
var $thumbs = $('.gallery-item').click(function(e) {
e.preventDefault();
//add the class to the currently clicked element (this)
$(this).toggleClass(classHighlight);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul class="gallery"><!--one ul is going to wrap all li's -->
<li class="gallery-item">
<figure class="img-wrapper fade">
<a class="img-box" href="#">
<img class="center-cropped" alt="gallery image" src="https://placehold.it/180x180.jpg">
</a>
</figure>
</li>
<li class="gallery-item">
<figure class="img-wrapper fade">
<a class="img-box" href="#">
<img class="center-cropped" alt="gallery image" src="https://placehold.it/180x270.jpg">
</a>
</figure>
</li>
<li class="gallery-item">
<figure class="img-wrapper fade">
<a class="img-box" href="#">
<img class="center-cropped" alt="gallery image" src="https://placehold.it/180x180.jpg">
</a>
</figure>
</li>
</ul>
你能解釋一下你需要的嗎? –
你的標題是「最多10個」,你的問題是「最多3個」? – Mark
[使用jQuery選擇第一個「n」項目的可能的重複項)(https://stackoverflow.com/questions/1865552/selecting-the-first-n-items-with-jquery) – Kaddath