localstorage 질문이요

localstorage 질문이요

QA

localstorage 질문이요

답변 1

본문

<div id="myDIV" onclick="lastTab()">
     <button class="btn">1</button>
     <button class="btn active">2</button>
     <button class="btn">3</button>
     <button class="btn">4</button>
     <button class="btn">5</button>
   </div>

 

<style>
      .btn {
        border: none;
        outline: none;
        padding: 10px 16px;
        background-color: #f1f1f1;
        cursor: pointer;
      }
      .active, .btn:hover {
        background-color: #666;
        color: white;
      }
   </style>

 

$('button.btn').click(function(){
   $('button.btn').removeClass("active");
   $(this).addClass("active");

      localStorage.setItem("btn", "active");
      var lastTab = localStorage.getItem("btn");
   });

 

이렇게 localstorage에 active 상태를 저장했다가 불러오는 방식으로 새로고침시

active 상태를 유지하려고 했는데 유지가 안되서요.

jquery 특정 파일이 필요한건가요?

<script src="https://code.jquery.com/jquery-3.5.1.js 현재는 이것만 적용되어 있는 상태입니다.

이 질문에 댓글 쓰기 :

답변 1

localStorage는 jquery와 관계가 없습니다.

저장하고 불러오고 할때 값을 로그로 찍어 보세요.

답변을 작성하시기 전에 로그인 해주세요.
전체 2
© SIRSOFT
현재 페이지 제일 처음으로