在jquery中使用切片时如何隐藏元素?

时间:2018-02-22 05:00:26

标签: jquery

这是我目前的代码:



$('.list-request-negotiating-loadmore').on('click', function(){
  $(".request-negotiating-item:hidden").slice(0, 3).show();
  if($(".request-negotiating-item:hidden").length < 3){
      $('.list-request-negotiating-loadmore').hide();
  }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dashboard-info list-requests request-negotiating" >
<div class="enquiry request-item request-negotiating-item" >1</div>
<div class="enquiry request-item request-negotiating-item" >2</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">3</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">4</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">5</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">6</div>
<div class="enquiry request-item request-negotiating-item" style="display: none;">7</div>
</div>
<div class="dashboard-title list-request-negotiating-loadmore loadmore" style="">load more</div>
&#13;
&#13;
&#13;

如果隐藏的div少于3个,我希望隐藏loadmore按钮,但由于某些原因我的代码无法正常工作。

1 个答案:

答案 0 :(得分:0)

您的代码似乎有效,但从用户体验来看,您不希望有更接近此的内容

&#13;
&#13;
esp
&#13;
$('.list-request-negotiating-loadmore').on('click', function(){
  $(".request-negotiating-item:hidden").slice(0, 3).show();
  if($(".request-negotiating-item:hidden").length < 1){
      $('.list-request-negotiating-loadmore').hide();
  }
});
&#13;
&#13;
&#13;