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:
-
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" ""});
-
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
Post a Comment