How to get the input and textarea values on change function using jquery
$('#filedset').find("select, input, textarea").change(function() { alert($(this).val()); });
if I use this code when I change anything on my dropdownlistbox I am getting alert but when I change anything on开发者_JS百科 my Input or textarea changed text i am getting on alert?
is that something i am doing wrong?
thanks
The change
events for these fire when they lose focus normally (e.g. click outside), if you want the handler to execute as you type, I recommend using the .keyup()
event instead (so you get the right value, keydown
would be the value without the current key taken into account).
Like this:
$('#filedset').find('select, input, textarea').bind('change keyup', function() {
alert($(this).val());
});
Or if you have lots of and/or dynamic elements, you can use .delegate()
, like this:
$('#filedset').delegate('select, input, textarea','change keyup', function() {
alert($(this).val());
});
精彩评论