Detecting input change in jQuery?

后端 未结 8 2146
Happy的楠姐
Happy的楠姐 2020-11-22 04:11

When using jquery .change on an input the event will only be fired when the input loses focus

In my case, I need to make a call to the serv

8条回答
  •  遥遥无期
    2020-11-22 04:19

    As others already suggested, the solution in your case is to sniff multiple events.
    Plugins doing this job often listen for the following events:

    $input.on('change keydown keypress keyup mousedown click mouseup', handler);

    If you think it may fit, you can add focus, blur and other events too.
    I suggest not to exceed in the events to listen, as it loads in the browser memory further procedures to execute according to the user's behaviour.

    Attention: note that changing the value of an input element with JavaScript (e.g. through the jQuery .val() method) won't fire any of the events above.
    (Reference: https://api.jquery.com/change/).

提交回复
热议问题