简体   繁体   English

如何根据从数据库中获取的项目数在每次单击按钮后动态显示div?

[英]How to show divs dynamically after each button click based on number of items fetched from database?

I have some data in my database. 我的数据库中有一些数据。 I will fetch the data and will use the count. 我将获取数据并使用计数。 Now I have to display this data one by one in a div. 现在,我必须在div中一一显示此数据。 So there will be first data and a next button. 因此,将有第一个数据和一个下一个按钮。 When I click on 'next' button,the second data fetched shows and so on until the end. 当我单击“下一步”按钮时,将显示读取的第二个数据,依此类推,直到最后。 At the end the next button disappears and another button appears. 最后,下一个按钮消失,另一个按钮出现。

PLS Note: I am using python flask as back end PLS注意:我正在使用python flask作为后端

How to do this??? 这个怎么做???

     <button type="button" class="btn btn-primary m-b-10 m-l-5" onclick="nextpart()" style="display:inline">Next ></button>
<div class="form-left-w3l" id="welcomeDiv1">
            <h6>Data : {{ id }}</h6>
        </div>
<div id="welcomeDiv2">
</div>

JS: JS:

function nextpart() {
               document.getElementById('welcomeDiv1').style.display = "none";
               document.getElementById('welcomeDiv2').style.display = "block";
               }

Save the data in an array. 将数据保存在数组中。 Create all the div s with a for-loop. 使用for循环创建所有div Make them all style="display:none" . 使它们全部为style="display:none"

Then .show() the first one and add a class like active to it. 然后.show()第一个,并向其中添加一个类似active的类。

Hook the Next-Button to a function: .hide() the active div and remove the active class form it. 将Next-Button挂钩到一个函数: .hide() active div并从中移除active类。 .show() the next sibling of that div and add the active class. .show()该div的下一个同级,并添加active类。

Use the same logic for the Prev-Button. 对上一个按钮使用相同的逻辑。

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

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