javascript - jQuery keydown event: Value coming delayed -


I have the following issues:

I have found an event listener on the input field. The value of the input field must be valid on every important event. The problem is that the value assigned to Event-Goal is delayed:

  1. You have an empty input field and type a letter:

     < Code> $ ('Form.registration') keydown (function (e) {var $ el = $ (e.target); if ($ el.val () == "") {$ el.closest ("div. Control-group "). AddClass (" Error ");} console.log ($ el.val ()); // This log" ""});    
  2. You type in the second letter

      $ ('form.registration'). KeyDown (function (e) {Var $ el = $ (e.target); if ($ el.val () == "") {$ el.closest ("div.control-group"). AddClass ("Error ");} Console.log ($ El.val ()); // it logs the first letter (for example:" a ")});    

    Div>

    I recommend that you use keyup instead instead it will stop your program from running intensively when the user presses the key And keeps it, then the content is being processed after the user's key is released. In many cases this method is very convenient.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -