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

206
Views
¿Podría alguien ayudarme con las funciones de limitación de un paso de 0.1 y sin caracteres y también un valor mínimo y máximo?

Aquí está el código que tengo hasta ahora y las funciones limitantes para las que quiero que la entrada rechace

  • un valor de paso de 0,1, es decir, ningún valor inferior a 0,1, es decir, 0,01
  • sin caracteres, es decir, w, r, t
  • un valor mínimo establecido por la función de entrada, es decir, 1
  • un valor máximo establecido por la función de entrada, es decir, 5
  • tenga en cuenta la forma en que he escrito el resto de mi código, el tipo de formulario de entrada no puede ser = "número", debe ser = "texto"

cualquier ayuda sería muy apreciada

 function myFunction(e, low, high) { console.log("called"); console.log("low" + low); console.log("high" + high); console.log(e.target.value + e.key); var charValue = String.fromCharCode(e.keyCode); var nextValue = e.target.value + e.key; if (((!/^(\d+)?([.]?\d{0,1})?$/.test(e.target.value + e.key)) && (e.which != 8)) && (nextValue < 1 || nextValue > 5)) { e.preventDefault() } }
 <!DOCTYPE html> <html> <form name="addtext"> SetPoint :<input id="setPoint" type="text" name="setPoint" onkeydown="myFunction(event,3, 5)" /><br /> </form>

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

0

A menos que juegue Code Golf, no hay premios por agrupar toda la lógica en una sola condición.

Divida la condición en múltiples declaraciones if para que pueda implementar su lógica claramente.

Debe reemplazar el 1 y el 5 codificados de forma rígida con low y high .

 function myFunction(e, low, high) { console.log("called"); console.log("low" + low); console.log("high" + high); var nextValue = e.target.value + e.key; console.log(nextValue); if (e.which == 8) { // allow backspace return; } if (!/^(\d+)?([.]?\d{0,1})?$/.test(nextValue)) { e.preventDefault(); // non-number, don't allow } if (nextValue < low || nextValue > high) { e.preventDefault(); } }
 <!DOCTYPE html> <html> <form name="addtext"> SetPoint :<input id="setPoint" type="text" name="setPoint" onkeydown="myFunction(event,3, 5)" /><br /> </form>

about 4 years ago · Juan Pablo Isaza Report

0

O bien, podría usar una entrada hecha para esto. No requiere javascript.

 <input id="range" value="1" type="range" step="0.1" min="0.1" max="5.0">

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!