gpt4 book ai didi

javascript - 创建上一页按钮

转载 作者:行者123 更新时间:2023-11-28 01:10:17 25 4
gpt4 key购买 nike

我正在尝试创建一种使用 PrevNext 按钮在页面之间导航的方法。这些按钮是使用 bootstrap 和字体超棒的图标制作的,可以在这里看到:Live Example

正在使用的软件是Comic Reader

我已经成功地使用以下代码创建了一个下一页按钮:

<a href="<?php echo $chapter->next_page($current_page); ?>" onClick="return nextPage();" >
<button type="button" class="btn btn-info" id="next-page"><i class="fa fa-chevron-right"></i></button>
</a>

我将如何创建一个与当前下一页的工作方式相同的上一页按钮页面?

我试过 history.goback 但就是这样,根据你的历史返回上一页。

非常感谢,

编辑:在下面添加了更多详细信息作为答案

最佳答案

您可以通过简单的 javascript 代码完成,如下所示:

HTML:

<a href="javascript:void(0);" onClick="return prevPage();" >Prev</a>

JavaScript:

function prevPage(){
//assuming that the current page count will always be at the end of URL
// /reader/read/test/en/0/0/page/10
//here current page number is 10
var currentPage = window.location.pathname.split("page/")[1];
var currentPage = parseInt(currentPage);
var prevPage = 1;
if(currentPage > 1)
prevPage = currentPage - 1;
else
return; //return if we are on 1st page

window.location.href = window.location.href.replace(currentPage,prevPage);
}

关于javascript - 创建上一页按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37967432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com