我使用https://github.com/javve/list.js和插件进行分页https://github.com/javve/list.pagination.js
如果只有一页,只想隐藏分页。什么是最好的方法呢?
我试过了:
var paging = document.getElementById('paging');
if (pages.length <= 1) {
paging.style.display = 'none';
}
不起作用。
以下是:http://codepen.io/anon/pen/RoVMYb
的示例页面var https://github.com/javve/list.pagination.js/blob/master/dist/list.pagination.js#L451
答案 0 :(得分:1)
请检查我修改过的代码段。要查看分页,请在page: 5
下方设置
var monkeyList = new List('test-list', {
valueNames: ['name'],
page: 15,
outerWindow:0,
plugins: [ ListPagination({}) ]
});
if((monkeyList.size()/monkeyList.page)<=1){
document.getElementsByClassName('pagination')[0].style.display = 'none';
}
.pagination li {
display:inline-block;
padding:5px;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script src="http://listjs.com/assets/javascripts/list.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/list.pagination.js/0.1.1/list.pagination.min.js"></script>
<div id="test-list">
<input type="text" class="search" />
<ul class="list">
<li><p class="name">Guybrush Threepwood</p></li>
<li><p class="name">Elaine Marley</p></li>
<li><p class="name">LeChuck</p></li>
<li><p class="name">Stan</p></li>
<li><p class="name">Voodoo Lady</p></li>
<li><p class="name">Herman Toothrot</p></li>
<li><p class="name">Meathook</p></li>
<li><p class="name">Carla</p></li>
<li><p class="name">Otis</p></li>
<li><p class="name">Rapp Scallion</p></li>
<li><p class="name">Rum Rogers Sr.</p></li>
<li><p class="name">Men of Low Moral Fiber</p></li>
<li><p class="name">Murray</p></li>
<li><p class="name">Cannibals</p></li>
</ul>
<ul class="pagination"></ul>
</div>
答案 1 :(得分:0)
getElementById没有长度参数, id是唯一的。试试这个:
var paging = document.getElementById('paging');
if (paging) {
paging.style.display = 'none';
}
答案 2 :(得分:0)
如果没有完整的代码,很难说,但我认为你有一些包含页数的变量,也许它甚至是'页面'。如果是这样,那么答案是:
$scope.data = {};