JQuery: change input events

I have a choice that I want to run with various functions depending on the one selected. I also used the flexselect http://rmm5t.github.com/jquery-flexselect/ plugin to convert the select box to a combo box. The result is an input field.

I want to run the function when changing the text of the input window, not on blur , but immediately. I see no way to do this. I can't just do keyup, because often the choice comes from the flexselect drop-down list and doesn't print. Using the change event requires the input field to be blurry, this is not the behavior that the user expects.

Is there a solution to this problem?

Thanks!

+3
source share
3 answers

This is a hack, but you can modify the flexselect.js file to raise a custom event when it changes the value of the text field. After any place in the file that calls "this.input.val (" (for example, line 231), insert: trigger ("myCustomEvent"), and then bind to it from your existing code:

$('#selector').bind('myCustomEvent',function(){
       alert('myCustomEvent');
});
+2
source

note that jquery bind () allows several events.

 $('#selector').bind('keyup mouseup change',function(e){
       alert(e.type);
});
+7
source

onblur onkeyup?

, (window.setTimeout) - , .

0

Source: https://habr.com/ru/post/1718356/


All Articles