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

384
Views
recorrer las casillas de verificación por nombre de clase en jquery

Necesito recorrer todas las casillas de verificación para configurar el botón deshabilitado o no. Si una de las casillas de verificación está marcada, entonces el botón está habilitado. Sin embargo, parece que mi código no pasó por la casilla de verificación. La alerta dentro de cada función no se muestra. Encontré el método de bucle en ¿Cómo recorrer un grupo de casillas de verificación que tienen el mismo nombre de clase?

Ahí está mi código:

 function setButton() { alert('line 24'); var blnDisable = true; //https://stackoverflow.com/questions/35506843/how-to-loop-through-group-of-check-boxes-that-have-same-class-name $('.chkItem').each(function (index, obj) { if (obj.checked == true) { alert('line 30'); blnDisable = false; } }); alert('disable=' + blnDisable); $("#btnDownload").attr("disabled", blnDisable); }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto hará que verifique si alguna de las casillas de verificación está marcada. Si es así, habilitará la casilla de verificación, si no, la deshabilitará. Por último, lo asigné a una función para que pueda ejecutarse al cargar la página. Esto es importante, por lo que comprobará automáticamente si el botón de descarga debe estar habilitado en la carga de la página.

 <input type="checkbox" class="chkItem" />one<br /> <input type="checkbox" class="chkItem" />two<br /> <input type="checkbox" class="chkItem" />three<br /> <button id="btnDownload">download</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script> var checkButton = function () { blnDisable = true; $('.chkItem').each(function (index, obj) { if (this.checked === true) { blnDisable = false; } }); $("#btnDownload").attr("disabled", blnDisable); }; $(".chkItem").on("change", checkButton); checkButton(); </script>
about 4 years ago · Santiago Trujillo 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!