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

230
Views
Numeración automática al presionar el teclado

Tengo una numeración automática cuando se presionan Ctrl y Enter . Mi problema actual es que, cuando comienzo mi numeración automática en el tercer cuadro de texto, mi segundo cuadro de texto se ve afectado. ¿Cómo puedo conservar los otros valores de mi cuadro de texto? El cuadro de texto antes de ellos no debe cambiar su valor.

Gracias.

 $(document).on('keyup', '.leg', function(e) { let value = parseInt(e.target.value); if ((e.ctrlKey || e.metaKey) && (e.keyCode == 17 || e.keyCode == 13)) { //loop through all values... $(".leg").each(function(i) { if (i !== 0) { $(this).val(++value); //assign new value.. $(this).trigger("change") //call your change event to handle further... } }) } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg">

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede crear una variable para realizar un seguimiento de si each ciclo ha cruzado o no el elemento de destino y luego solo modificar el valor de la entrada cuando sea verdadero. Esto asegurará que solo modifique las entradas después del objetivo.

Ver runChange en el ejemplo:

 $(document).on('keyup', '.leg', function(e) { let value = parseInt(e.target.value); if ((e.ctrlKey || e.metaKey) && (e.keyCode == 17 || e.keyCode == 13)) { //loop through all values... let runChange = false; $(".leg").each(function(i, el) { if (runChange) { $(this).val(++value); //assign new value.. $(this).trigger("change") //call your change event to handle further... } if (e.target == el) runChange = true; }) } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg">

about 4 years ago · Santiago Trujillo Report

0

Intente dejar de verificar la entrada 0 'ésima y cambie todas las entradas cada vez:

 $(document).on('keyup', '.leg', function(e) { let value = parseInt(e.target.value); const inputIndex = $(this).index() - 1; if ((e.ctrlKey || e.metaKey) && (e.keyCode == 17 || e.keyCode == 13)) { //loop through all values... $(".leg").each(function(i) { if (i !== inputIndex) { $(this).val(++value); //assign new value.. $(this).trigger("change") //call your change event to handle further... } }) } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg"> <input type="text" class="leg">

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!