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

312
Views
TypeError no capturado: no se pueden leer las propiedades de undefined (leyendo 'preventDefault')

Active el atributo onchange en la entrada según un proceso específico. Sin embargo, incluso si utilizo "Evento" como parámetro, sigo recibiendo el siguiente error. Además, alternativamente, probé Event.StopPropagation () y Return False pero el problema continúa.

 $(function () { test(); }); function test(obj) { var inputValue = parseInt($(obj).val()); if (($(obj).val() < 0 || $(obj).val() > 100) && event.keyCode !== 46 // keycode for delete && event.keyCode !== 8 // keycode for backspace ) { event.preventDefault(); $(obj).val(0); } else if (isNaN(inputValue)) { event.preventDefault(); $(obj).val(0); } }
 <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script> <div> <input id="weightInput" type="number" class="form-control weightInput" data-key="" data-guid="" onchange="test(this)" value="" /> </div>

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

0

Debe pasar el event como un argumento explícito al argumento onchange .

Tampoco deberías llamarlo desde $(function() { }) , ya que no hay ningún evento allí.

 function test(obj, event) { var inputValue = parseInt($(obj).val()); if (($(obj).val() < 0 || $(obj).val() > 100) && event.keyCode !== 46 // keycode for delete && event.keyCode !== 8 // keycode for backspace ) { event.preventDefault(); $(obj).val(0); } else if (isNaN(inputValue)) { event.preventDefault(); $(obj).val(0); } }
 <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script> <div> <input id="weightInput" type="number" class="form-control weightInput" data-key="" data-guid="" onchange="test(this, event)" value="" /> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Debería usar el oyente de jQuery para manejar el evento que no está definido en su código actual. También debe usar el objetivo de eventos como su objeto

 /***This here**/ jQuery(document).on('change','#weightInput',test); function test(event) { let obj = event.target var inputValue = parseInt($(obj).val()); if (($(obj).val() < 0 || $(obj).val() > 100) && event.keyCode !== 46 // keycode for delete && event.keyCode !== 8 // keycode for backspace ) { event.preventDefault(); $(obj).val(0); } else if (isNaN(inputValue)) { event.preventDefault(); $(obj).val(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!