Frage

Is it possible to bind keyup() to an entire <form>? For example, I have multiple <input type="text"> fields inside a form, and I want to bind a keyup event to all of them without having to attach a keyup event handler to each one. Rather, I want to bind one keyup event handler to all of them so if any of the text fields detect a keyup event, the event handler will run. Is this possible in jQuery?

I tried:

$('form').keyup(function() {...});

But that made the keyup event handler fire indefinitely after typing one character.

War es hilfreich?

Lösung

I don't think this is possible, but you are able to bind the same keyup event to all the inputs at once:

$('#myform input[type=text]').on('keyup', /* yada */);

Andere Tipps

You may try something Like this: Fast Demo

$(function(){
   //create one instance for handler:
   var myHandler = function(e){ /* Your function */ };

   //Bind it:
   $("#form input[type=text]").on('keyup',function(e){ myHandler(e);  });

});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top