首页  >  问答  >  正文

HTML:如何按升序转到下一页?

我在名为 Project 的文件夹中有一些具有数字名称的 HTML 文件,如下所示:

230512.html
230519.html
230530.html
230630.html
240120.html

我想在每个文件中添加一个“下一页按钮”。当我单击该按钮时,超链接会将我带到按升序排列的下一个页面。

因此,如果我在 230530.html 中,单击下一页按钮 应该会将我带到 230630.html

文件名基本上是 YYMMDD.html 格式的日期。日期可能不连续。

有什么想法,如何创建这样的脚本吗?

P粉256487077P粉256487077376 天前622

全部回复(1)我来回复

  • P粉455093123

    P粉4550931232023-09-11 18:40:19

    这里有一些代码:

    // get current filename
    let currentFileName = location.pathname.split('/').pop();
    
      // Get the list of all HTML files in the "Project" folder
      let fileNames = [
        '230512.html',
        '230519.html',
        '230530.html',
        '230630.html',
        '240120.html'
      ];
    
      // Find the index of the current file in the list
      let currentIndex = fileNames.indexOf(currentFileName);
    
      // Calculate the index of the next file
      let nextIndex = (currentIndex + 1) % fileNames.length;
    
      // Get the name of the next file
      let nextFileName = fileNames[nextIndex];

    如果您在最后一页,nextFileName 将返回到索引 0。

    回复
    0
  • 取消回复