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

153
Views
evitar keyup cuando entrada foco

Intento activar algo con la tecla de la barra espaciadora, pero la barra espaciadora debe evitar que se dispare cuando la entrada es el foco.

Lo estoy intentando de esta manera, pero no funciona bien. ¿Hay alguna sugerencia de cómo hacerlo bien?

 $(document).ready(function(){ $('input').on('blur', function(){ $(document).on('keyup', function(e){ if(e.keyCode == 32){ alert("pressed!"); } }); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <label> Name</label> <input type="text" /> <br /> <label>Pass</label> <input type="text" /> </form>

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Separe el controlador con .off() mientras la entrada tiene el foco:

 $(function(){ $(document).on('keyup', function(e) { if(e.keyCode == 32){ alert("pressed!"); } }); $('input').on('focus', function() { $(document).off('keyup'); }); $('input').on('blur', function() { $(document).on('keyup', function(e) { if(e.keyCode == 32){ alert("pressed!"); } }); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <label> Name</label> <input type="text" /> <br /> <label>Pass</label> <input type="text" /> </form>

over 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!