jquery change not working incase of dynamic value change

后端 未结 4 1802
抹茶落季
抹茶落季 2021-01-02 17:24

In jQuery how can I track onchange event if the value of textbox is changing dynamically from some other event. I tried this but its not working:



        
4条回答
  •  伪装坚强ぢ
    2021-01-02 18:06

    keyup doesn't cover all natural cases :(

    Two cases when change and keyup won't work:

    • browser form autocomplete mechanisms
    • mouse-performed paste from system clipboard.

    Example: form has textbox intended to put an email address into it, and onchange, keyup events are attached to it.

    When user starts typing an email address, if e.g. Chrome or Firefox autocomplete box pops up and user clicks one of the options, the box gets filled with the value, focus stays within the textbox (so no change event firing) and no key was pressed (no keyup event). I tried attaching click to the list, but it causes weird behavior in my browser.

    Similar with pasting - if mouse is used for pasting (through contextual menu available on right mouse click)), neither keyup nor change events are fired.

    Anyone has a complete solution for this, i.e. how to handle actual changes of the value of the input?

提交回复
热议问题