Javascript 如何使“加载更多”按钮显示其他行?

Javascript 如何使“加载更多”按钮显示其他行?,javascript,html,jquery,Javascript,Html,Jquery,我无法获取页面的正确代码 我有6行,每行3列,充满了图像。当我点击“加载更多”按钮时,它什么也不做。我试图更改jquery代码。从0、3到0、6等等,但什么都没有。我只需要显示2或3行,然后单击“加载更多”按钮,再显示2或3行 $document.readyfunction{ $.row.slice0,3.show; $loadMore.onclick,function e{ e、 防止违约; $.row:hidden.slice0,3.slideDown; 如果$.row:hidden.le

我无法获取页面的正确代码

我有6行,每行3列,充满了图像。当我点击“加载更多”按钮时,它什么也不做。我试图更改jquery代码。从0、3到0、6等等,但什么都没有。我只需要显示2或3行,然后单击“加载更多”按钮,再显示2或3行

$document.readyfunction{ $.row.slice0,3.show; $loadMore.onclick,function e{ e、 防止违约; $.row:hidden.slice0,3.slideDown; 如果$.row:hidden.length==0{ $loadMore.textNo Content.addClassnoContent; } }; }
你可以用两种方法

first-最初隐藏所有行,然后显示前3行

$(document).ready(function(){
$(".row").hide(); //add this line
$(".row").slice(0, 3).show();
$("#loadMore").on("click", function(e){
 e.preventDefault();
 $(".row:hidden").slice(0, 3).slideDown();
 if($(".row:hidden").length == 0) {
   $("#loadMore").text("No Content").addClass("noContent");
 }
});

})
第二-先隐藏最后三个

$(document).ready(function(){
$(".row").slice(3, 6).hide();//change this line
$("#loadMore").on("click", function(e){
 e.preventDefault();
 $(".row:hidden").slice(0, 3).slideDown();
 if($(".row:hidden").length == 0) {
   $("#loadMore").text("No Content").addClass("noContent");
 }
});

})

你可以用两种方法

first-最初隐藏所有行,然后显示前3行

$(document).ready(function(){
$(".row").hide(); //add this line
$(".row").slice(0, 3).show();
$("#loadMore").on("click", function(e){
 e.preventDefault();
 $(".row:hidden").slice(0, 3).slideDown();
 if($(".row:hidden").length == 0) {
   $("#loadMore").text("No Content").addClass("noContent");
 }
});

})
第二-先隐藏最后三个

$(document).ready(function(){
$(".row").slice(3, 6).hide();//change this line
$("#loadMore").on("click", function(e){
 e.preventDefault();
 $(".row:hidden").slice(0, 3).slideDown();
 if($(".row:hidden").length == 0) {
   $("#loadMore").text("No Content").addClass("noContent");
 }
});

})

我不知道jQuery,但我是用标准JavaScript编写的,希望能有所帮助

        document.querySelector('#loadMore').addEventListener('click', (button) =>{
            //Set number of rows to show
            const numRowsToShow = 2
            for (let i = 0; i < numRowsToShow; i++) {
                
                //Get the next row non visible (.d-none)
                let rowToShow = document.querySelector('.row.d-none')
                
                //If nothing's found change the text of the link and exit the loop
                if(!rowToShow){
                    
                    button.target.text = 'No Content'
                    button.classList.add('noContent')
                    break;                    
                } 

                //show the row
                rowToShow.classList.remove('d-none')
            }
        })

我不知道jQuery,但我是用标准JavaScript编写的,希望能有所帮助

        document.querySelector('#loadMore').addEventListener('click', (button) =>{
            //Set number of rows to show
            const numRowsToShow = 2
            for (let i = 0; i < numRowsToShow; i++) {
                
                //Get the next row non visible (.d-none)
                let rowToShow = document.querySelector('.row.d-none')
                
                //If nothing's found change the text of the link and exit the loop
                if(!rowToShow){
                    
                    button.target.text = 'No Content'
                    button.classList.add('noContent')
                    break;                    
                } 

                //show the row
                rowToShow.classList.remove('d-none')
            }
        })
有帮助吗

$document.readyfunction{ 变量行=$.row.toArray; $.row.hide; $rows.0,1.show; $document.onclick,loadMore,function{ e、 防止违约; 如果!行数。长度{ $loadMore.textNo Content.addClassnoContent; }否则{ $this.remove; $rows.0,1.slideDown; } } } 有帮助吗

$document.readyfunction{ 变量行=$.row.toArray; $.row.hide; $rows.0,1.show; $document.onclick,loadMore,function{ e、 防止违约; 如果!行数。长度{ $loadMore.textNo Content.addClassnoContent; }否则{ $this.remove; $rows.0,1.slideDown; } } }

我给你编了一段。请从中创建一个新的行。看起来,您只是使隐藏行可见,而不是真正加载新行。这有什么意义吗?非常感谢,但我不能解决它,没关系,我会尝试其他方法。@mplungjan谢谢你,第二次使用堆栈溢出和英语它不是我的母语language@kristipapaqako如果你按照我给你的建议去做,你的英语还可以:我给了你一个片段。请从中创建一个新的行。看起来,您只是使隐藏行可见,而不是真正加载新行。这有什么意义吗?非常感谢,但我不能解决它,没关系,我会尝试其他方法。@mplungjan谢谢你,第二次使用堆栈溢出和英语它不是我的母语language@kristipapaqako如果你按照我给你的建议去做,你的英语就可以了:非常感谢,但我不能解决它,没关系,我会试试别的。@kristipapaqako为什么不能修好?1分钟,我会试试的again@kristipapaqako您的代码的HTML结构与我的代码片段中的类似吗?是的,如果可能的话,我可以给您发送一封包含我的工作的电子邮件以更好地查看它吗?因为我找不到问题。非常感谢您,但我无法修复它,没关系,我会试试别的。@kristipapaqako为什么不能修好?1分钟,我会试试的again@kristipapaqako您的代码的HTML结构与我的代码片段中的类似吗?是的,如果可能的话,我可以给您发送一封包含我的工作的电子邮件以更好地查看它吗?因为我找不到问题。非常感谢您,但我无法修复它,没关系,我会试试别的。非常感谢,但我修不好,没关系,我会试试别的。非常感谢,但我修不好,没关系,我会试试别的。非常感谢,但我修不好,没关系,我会试试别的。