250x250
Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

개린이 개발노트

힘든 하루 쉽지만 어려워 어렵지만 어렵다 본문

개발자 중얼중얼

힘든 하루 쉽지만 어려워 어렵지만 어렵다

개린이9999 2023. 8. 14. 21:07
728x90

 

$(document).ready(function(){
  
  if(localStorage.getItem("lang") == null) {
    localStorage.setItem("lang", 'kor');
  }

  $("#selectlang").val(localStorage.getItem("lang"));

  $("#selectlang").on('change', function(e){
    let value = e.currentTarget.value;
    
    $(this).val(value).prop("selected", true);
    localStorage.setItem("lang", value);

    test();
  });
});


  function test(){
        
    const test = document.getElementById('selectlang');
    let url = '';
    
    if(test.value == 'kor'){
      url = "/";
    }else if (test.value == 'eng'){
      url = "/eng";
    }

    location.href = url;


  };

한글-> 영어 select 박스 선택하면 영어페이지로

영어->한글 select 박스 선택하면 한글 페이지로

 

처음에 한글페이지에서 영어페이지로 변경 됐지만.. 리로드 하는 과정에서 English가 날라가서 고생했다.

localstorage 이용해서 선택된 값을 담았다. 근데 이게 끝이아니었다.

아예 맨처음에 null 상태에선 공란으로 select박스가 표시되었다.

그래서 null 일경우 kor을 넣어주어서 해결했다. 

728x90

'개발자 중얼중얼' 카테고리의 다른 글

인천공항에서 역사를 만나다  (0) 2024.08.11
JWT - Json Web Token  (0) 2023.08.24
CMD(명령 프롬프트) 명령어 모음  (0) 2023.07.19
인증 취약점 조치방법  (0) 2023.05.23
주니어 개발자를 위한 Tip  (0) 2023.04.06