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

283
Views
jQuery para aceptar solo valores entre 1 y 100 en elementos editables

¿Cómo puedo permitir solo valores entre 1 y 100 en las celdas td de mi tabla HTML?

Actualmente, tengo una función jquery que solo permite números,

 //only allow numbers in td $(".allow_only_numbers").keydown(function (e) { if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 || ((e.keyCode == 65 || e.keyCode == 86 || e.keyCode == 67) && (e.ctrlKey === true || e.metaKey === true)) || (e.keyCode >= 35 && e.keyCode <= 40)) { return; } if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } });

Sin embargo, solo quiero valores que oscilen entre 1 y 100.

El td es editable en contenido y las celdas que solo quiero que contengan dichos valores tienen una clase llamada allow_only_numbers, por ejemplo

 <td contenteditable='true' class="allow_only_numbers">-</td>

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

0

yo haría algo como esto

 $(".allow_only_numbers").keydown(function (e) { if($(".allow_only_numbers").innerText < 100 && $(".allow_only_numbers").innerText >= 1 ) { if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 || ((e.keyCode == 65 || e.keyCode == 86 || e.keyCode == 67) && (e.ctrlKey === true || e.metaKey === true)) || (e.keyCode >= 35 && e.keyCode <= 40)) { return; } else if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { e.preventDefault(); } } else alert('number out of range') });
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!