How to detect a textbox's content has changed

后端 未结 15 2034
猫巷女王i
猫巷女王i 2020-11-22 16:10

I want to detect whenever a textbox\'s content has changed. I can use the keyup method, but that will also detect keystrokes which do not generate letters, like the arrow ke

15条回答
  •  情深已故
    2020-11-22 16:13

    Start observing 'input' event instead of 'change'.

    jQuery('#some_text_box').on('input', function() {
        // do your stuff
    });
    

    ...which is nice and clean, but may be extended further to:

    jQuery('#some_text_box').on('input propertychange paste', function() {
        // do your stuff
    });
    

提交回复
热议问题