Can jQuery check whether input content has changed?

前端 未结 9 1039
轮回少年
轮回少年 2020-12-23 19:30

Is it possible to bind javascript (jQuery is best) event to \"change\" form input value somehow?

I know about .change() method, but it does not trigger

9条回答
  •  庸人自扰
    2020-12-23 20:11

    There is a simple solution, which is the HTML5 input event. It's supported in current versions of all major browsers for elements and there's a simple workaround for IE < 9. See the following answers for more details:

    • jQuery keyboard events
    • Catch only keypresses that change input?

    Example (except IE < 9: see links above for workaround):

    $("#your_id").on("input", function() {
        alert("Change to " + this.value);
    });
    

提交回复
热议问题