请帮帮我如何隐藏3个元素之后的所有元素?
$('.pagination_number').eq(3).nextAll('.pagination_number').hide()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a href="#" class="pagination_list pagination_number" data-number="1">1</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="2">2</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="3">3</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="4">4</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="5">5</a></li>
&#13;
答案 0 :(得分:1)
这个脚本隐藏3个以上的元素。将点变换滑块移到li
$(' .pagination_number:gt(2) ').hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a href="#" class="pagination_list pagination_number" data-number="1">1</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="2">2</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="3">3</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="4">4</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="5">5</a></li>
带有标记
li
的
$('li:gt(2) ').hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a href="#" class="pagination_list pagination_number" data-number="1">1</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="2">2</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="3">3</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="4">4</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="5">5</a></li>
答案 1 :(得分:0)
选择类pagination_number
,这将返回类pagination_number
的元素数组。从第三个元素循环遍历数组,然后选择父元素并隐藏。
更新了摘录:
var lists = $('.pagination_number');
//index to start hiding your elements from
var indexTostartHide = 3;
for(var i = indexTostartHide; i<lists.length; i++){
lists.eq(i).parent().hide();
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a href="#" class="pagination_list pagination_number" data-number="1">1</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="2">2</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="3">3</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="4">4</a></li>
<li><a href="#" class="pagination_list pagination_number" data-number="5">5</a></li>
&#13;