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

159
Views
¿Cómo puedo hacer que "input type="checkbox" conserve el valor de los datos?

¿Cómo puedo reescribir este código:

 var toggle = document.getElementById("test_switch"); var storedTheme = localStorage.getItem('theme') || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"); if (storedTheme) document.documentElement.setAttribute('data-theme', storedTheme) toggle.onclick = function() { var currentTheme = document.documentElement.getAttribute("data-theme"); var targetTheme = "light"; if (currentTheme === "light") { targetTheme = "dark"; } document.documentElement.setAttribute('data-theme', targetTheme) localStorage.setItem('theme', targetTheme); };

así que esto conserva sus marcas de verificación:

 <label for="mode_test"> <input type="checkbox" id="test_switch"> </label>

Me topé con el código anterior en una publicación de blog que incluía almacenamiento local y (prefiere-color-scheme: oscuro) en su implementación del modo oscuro, simplemente no sé cómo conciliar eso con el uso de casillas de verificación.

Gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede acceder al valor de la casilla de verificación con .checked

 var toggle = document.getElementById("test_switch"); console.log(toggle.checked) //returns true||false

Con esto, puede verificar fácilmente lo que está verificado actualmente.

about 4 years ago · Juan Pablo Isaza Report
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!