【问题标题】:Previous/next file with indexOf jquery?indexOf jquery的上一个/下一个文件?
【发布时间】:2018-12-27 09:20:39
【问题描述】:

我正在尝试创建一个从不同目录加载文件的上一个/下一个画廊样式菜单(基于窗口 url)。 我使用 php include 作为菜单(在所有页面上),然后使用 jquery 在每个页面上加载脚本,但问题是 if/else 每次都从开始运行,弄乱了结构。有什么更好的方法来做到这一点? (基本上当代码再次运行时,它不会移动到下一个 else-if 以对应/同步到当前窗口 url)

        if (window.location.href.indexOf("page1") > -1){
            $(".next").attr('href', "portfolio/page2/");
        }
        else if (window.location.href.indexOf('page2')){
            $(".previous").attr('href', "portfolio/page1/");
            $(".next").attr('href', "portfolio/page3/");
        }
        else if (window.location.href.indexOf('page3')){
            $(".previous").attr('href', "portfolio/page2/");
            $(".next").attr('href', "portfolio/page4/");
        }

【问题讨论】:

    标签: jquery menu pagination load indexof


    【解决方案1】:

    似乎我必须在每个 else if 语句上添加 > -1 或 != -1 才能使它起作用:

    window.location.href.indexOf("page2") > -1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多