如何在模式引导程序中加载 jQuery4



所以我有这段代码,在单击我的页面中工作的按钮后,可以很好地加载 10 篇额外的"文章"。

$(function(){
$(".trick-show").slice(0, 10).css('display', 'flex'); // select the first ten
$("#loadMore").click(function(e){ // click event for load more
e.preventDefault();
$(".trick-show:hidden").slice(0, 5).css('display', 'flex'); // select next 5 hidden tricks and show them
if($(".trick-show:hidden").length === 0){ // check if any hidden tricks still exist
$("#loadMore").attr('disabled', 'disabled'); // Add disabled on button after the last trick is shown
alert("It was your last load ! No more tricks to show..."); // alert if there are none left
}
});
});

问题是当我在引导 4 模式中使用相同的 jQuery 代码时。它正在很好地改变第一篇文章的显示,但是当单击按钮时它不会做任何事情。我想添加一个setTimeout或使用show.bs.modal,但我不知道确切的位置。

提前感谢您的帮助,

试试 JQuery .on(( 方法

$(document).on("click", "#loadMore", function(event){
event.preventDefault();
$(".trick-show:hidden").slice(0, 5).css('display', 'flex'); // select next 5 hidden tricks and show them
if($(".trick-show:hidden").length === 0){ // check if any hidden tricks still exist
$("#loadMore").attr('disabled', 'disabled'); // Add disabled on button after the last trick is shown
alert("It was your last load ! No more tricks to show..."); // alert if there are none left
}
});

最新更新