开发者

How to know when a textbox changes (without waiting for blur)?

I have an <input> textbox.

I wish to call a function when it has been modified. The default behavior of the change event is to only trigger on blur, but I need to call my function as soon as the textbox's text changes and can't wait for blur.

I'm not sure the best way to do this. I thought of maybe handling keydown and then testing the value of the keyCode for a key that would modify the value. So... ignore arrow keys, etc. But that seems awkward and I don't think I can figure out the test to make it work.

I also thought about recording the inital value and comparing to this value but then I wouldn't be notified in the case when the value changes back to the orig开发者_开发问答inal.

Maybe there's a better way?

I'd appreciate any suggestions.


a combination of focus and keyup is probably your best bet. record the initial value in the focus handler, and check against the current value in the keyup handler. (the new input value, if any, is available when keyup fires).


You can use the keypress function.


You can use the change() function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜