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

358
Views
Cómo obtener el estado actual del interruptor de palanca (verdadero/falso) en Javascript

Tengo un conmutador de conmutación múltiple que proviene del código PHP/Mysql, quiero mostrar el div en ese conmutador que actualmente está activado .

Además, quiero mostrar/ocultar div cuando ese interruptor de encendido/apagado

ingrese la descripción de la imagen aquí

Mi código Php:

 <li> <?php echo $_ship_method_value['shipping_title'];?> <label class="switch"> <!-- Toggled Case --> <input type="checkbox" id="toggd" name="toggle" value="<? echo $_ship_method_value['shipping_id']; ?>" class='cmn-toggle cmn-toggle-round' data-switchery <? if(array_key_exists("shipping_available",$_ship_method_value)) echo 'checked'; ?> /> <span class="slider round hide-off"></span> </li> <div class="show-hide"> <p>Want to show this div ;-)</p> </div>

Mi código jQuery

 $('input[name=toggle]').change(function(){ var mode = $(this).prop('checked'); if(mode == true){ $(".show-hide").show(); }else{ $(".show-hide").hide(); } });'

pero este código solo funciona al hacer clic en alternar para el evento de alternar único.

Por favor, ayúdame a encontrar la solución. ¡Gracias!

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

0

 $('.toggle_check_box').change(function(){ var mode = $(this).prop('checked'); if(mode == true){ $(".show-hide").show(); }else{ $(".show-hide").hide(); } });

puede aplicar la clase para su casilla de verificación y usarla así ... Esto alternará div en todos los botones de cambio

about 4 years ago · Juan Pablo Isaza Report

0

 $('body').on('change', 'input[name=toggle]', function() { var mode = $(this).prop('checked'); if (mode == true) { $(".show-hide").show(); } else { $(".show-hide").hide(); } });

** Actualizar **

Si div se encuentra junto a li, entonces el siguiente código funcionará para usted.

 $('body').on('change', 'input[name=toggle]', function() { var mode = $(this).prop('checked'); if (mode == true) { $(this).closest("li").next(".show-hide").show(); } else { $(this).closest("li").next(".show-hide").hide(); } });
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!