javascript - Check input when text is changed -


I have a question about when input text should be replaced, I use this as the keydown :

  $ ('# query'). Keydown (function () {console.log ($ (this) .val ());});   

but the actual value is query , then the console log will be quer . This is always a delay, I do not know why?

There are 3 ways to apply it.

The first is using the other events like input or propertychange . Note that propertychange is only supported on IE and input is supported on modern browsers.

  $ ('# query'). 'Input perpertychange', function () {console.log ($ (this) .val ());});   

The other way is to console.log ($ (this) .val ()); in setTimeout statement. You can get what you are typing. (Reason? I'm sorry, I do not really know why, use it);

  $ ('# query'). Keydown (function () {var query = $ (this); settimeout (function () {console.log (query.val ());}, 0);});   

and the last time using textchange events like this:

  $ ('# query'). ('Textchange', function () {console.log ($ (this) .val ());});    

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -