Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Guardar el estado del contador y elementos activos

Hola a todos, tengo una pregunta, ¿cómo puedo guardar el estado de las tarjetas activas, así como los valores de los contadores? La lógica es tarjeta activa + 1 , difiere del resto en el estilo, haga clic repetidamente en la misma tarjeta - 1 , el estilo vuelve a su estado original. En este momento solo estoy guardando el valor de las tarjetas en las que se hizo clic. Pero necesito que todo permanezca en su lugar después de recargar la página.

ejemplo de código

 const counter: HTMLDivElement = <HTMLDivElement>document.querySelector('.counter'); const activeCard = get('cardState'); [image].forEach((el) => { el.onclick = (evt) => { evt.preventDefault(); const active = el.classList.toggle(style.otherImgActive); if (el.classList.contains(style.otherImgActive)) { set('cardState', (shopCart.innerHTML = `${Number(shopCart.innerHTML) + 1}`)); } else { set('cardState', (shopCart.innerHTML = `${Number(shopCart.innerHTML) - 1}`)); } }; });

fucn responsable del almacenamiento local

 const set = (name: string, value: string) => { window.localStorage.setItem(name, JSON.stringify(value)); }; const get = (name: string) => { return JSON.parse(window.localStorage.getItem(name) || subStr); }; const remove = (name: string) => { localStorage.removeItem(name); }; const clean = () => { localStorage.clear(); };
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!