简体   繁体   English

如何使用 Javascript 隐藏分页

[英]How to hide pagination with Javascript

I am trying to hide my bootstrap pagination bar if the search results in less than one page of items.如果搜索结果少于一页的项目,我试图隐藏我的引导程序分页栏。

this is my home.html pagination:这是我的 home.html 分页:

<div class="pagination" id="paginationField">
            <nav aria-label="...">
                <ul class="pagination", id="pagination">
                    <li class="page-item {% if not prev_page_url %}disabled {% endif %} ">
                        <a class="page-link" href="{{ prev_page_url }}" tabindex="-1">Previous</a>
                    </li>
                    {% for n in page.paginator.page_range %}
                        {% if page.number == n %}
                            <li class="page-item active">
                                <a class="page-link" href="?page={{ n }}">{{ n }} <span class="sr-only">(current)</span></a>
                            </li>
                        {% elif n > page.number|add:-3  and n < page.number|add:3 %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ n }}">{{ n }}</a>
                            </li>
                        {% endif %}
                    {% endfor %}
                  
                  <li class="page-item {% if not next_page_url %}disabled {% endif %} ">
                    <a class="page-link" href="{{ next_page_url }}">Next</a>
                  </li>
                </ul>
            </nav>
        </div>

Here is my js file:这是我的 js 文件:

function showHidePagination() {
if(document.getElementById('paginationField').length > 15) {
    document.getElementById('pagination').style.display='none';
} else {
    document.getElementById('pagination').style.display='block';
}

} }

probably need to check for document.getElementById('paginationField').可能需要检查 document.getElementById('paginationField')。 innerHTML .length instead of document.getElementById('paginationField').length innerHTML .length 而不是 document.getElementById('paginationField').length

Only show paginator if count is greater then 1如果计数大于 1,则仅显示分页器

use

{% if  page.paginator.count>1 %} 

     <div class="pagination" id="paginationField">
        <nav aria-label="...">
         .....

{% endif %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM