편집 기록

편집 기록
  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.06.28

    혹시 prev버튼 next버튼있다고 하면 prev버튼을 눌렀을떄 i--, next버튼을 눌렀을떄 i++ 가 되도록하여 URL을 변경할 수 있나요?


    var prevBtn = document.getElementById("prev");
    var nextBtn = document.getElementById("next");
    var i = 0;
    var getPathname = window.location.pathname;
    var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
    
    function minus(){
        i--;
        if ( i === -1){
            i = 0;
        }
        // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
        // window.location.href = repetitivePath + i + ".html";
        window.location.replace(repetitivePath + i + '.html');
        console.log(i);
        // console.log(repetitivePath);
    }
    
    function plus(){
        i++;
        if ( i === 3){
            i = 2;
        }
        // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
        // window.location.href = repetitivePath + i + ".html";
        window.location.replace(repetitivePath + i + '.html');
        console.log(i);
        // console.log(repetitivePath);
    }
    
    
    prevBtn.addEventListener("click", function(){
        minus();
    })
    
    nextBtn.addEventListener("click", function(){
        plus()
    })
    

    총 파일은 이 코드가 있는 index.html과 바뀔 페이지 파일들인 1.html, 2.html, 3.html로 구성. prev버튼을 눌렀을때 -> i값이 -1되면서 현재 주소의 인덱스값+1 로 하여 i의 값과 ".html" 문자열을 합하여 주소를 변경. next버튼을 눌렀을때 -> i값이 +1되면서 나머지 동일.
    처음에 next버튼을 눌렸을때 1.html로는 이동이 됩니다만 2.html로는 더이상 진행이 안됩니다.

    어떤 식으로 접근하면 이 문제를 해결 할 수 있을까요? 선배님의 지적 부탁드립니다!

  • 프로필 김선우님의 편집
    날짜2018.06.28

    혹시 prev버튼 next버튼있다고 하면 prev버튼을 눌렀을떄 i--, next버튼을 눌렀을떄 i++ 가 되도록하여 URL을 변경할 수 있나요?


    var prevBtn = document.getElementById("prev");
    var nextBtn = document.getElementById("next");
    var i = 0;
    var getPathname = window.location.pathname;
    var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
    
    function minus(){
        i--;
        if ( i === -1){
            i = 0;
        }
        // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
        // window.location.href = repetitivePath + i + ".html";
        window.location.replace(repetitivePath + i + '.html');
        console.log(i);
        // console.log(repetitivePath);
    }
    
    function plus(){
        i++;
        if ( i === 3){
            i = 2;
        }
        // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
        // window.location.href = repetitivePath + i + ".html";
        window.location.replace(repetitivePath + i + '.html');
        console.log(i);
        // console.log(repetitivePath);
    }
    
    
    prevBtn.addEventListener("click", function(){
        minus();
    })
    
    nextBtn.addEventListener("click", function(){
        plus()
    })
    

    이 인덱스 파일을 포함해서 1.html, 2.html, 3.html에 똑같은 html태그를 넣어놓고 changePage.js라고 공통으로 연결해놨어요 ( 이건 페이지가 변경됐을때 i의 값이 저장이 될거라 생각하고 ) 혹시 next 버튼을 눌렸을때 다음 페이지로 넘어가되 prev버튼을 눌렸을때 이전 페이지로 갈 수 있게끔 할 수 있는 방법이 있나요?

  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.06.27

    혹시 prev버튼 next버튼있다고 하면 prev버튼을 눌렀을떄 i--, next버튼을 눌렀을떄 i++ 가 되도록하여 URL을 변경할 수 있나요?


    var prevBtn = document.getElementById("prev"); var nextBtn = document.getElementById("next"); var i = 0; var getPathname = window.location.pathname; var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);

    function minus(){ i--; if ( i === -1){ i = 0; } // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1); // window.location.href = repetitivePath + i + ".html"; window.location.replace(repetitivePath + i + '.html'); console.log(i); // console.log(repetitivePath); }

    function plus(){ i++; if ( i === 3){ i = 2; } // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1); // window.location.href = repetitivePath + i + ".html"; window.location.replace(repetitivePath + i + '.html'); console.log(i); // console.log(repetitivePath); }

    prevBtn.addEventListener("click", function(){ minus(); })

    nextBtn.addEventListener("click", function(){ plus() })

    이 인덱스 파일을 포함해서 1.html, 2.html, 3.html에 똑같은 html태그를 넣어놓고 changePage.js라고 공통으로 연결해놨어요 ( 이건 페이지가 변경됐을때 i의 값이 저장이 될거라 생각하고 ) 혹시 next 버튼을 눌렸을때 다음 페이지로 넘어가되 prev버튼을 눌렸을때 이전 페이지로 갈 수 있게끔 할 수 있는 방법이 있나요?