开发者

How to get the input and textarea values on change function using jquery

开发者 https://www.devze.com 2023-01-04 17:27 出处:网络
$(\'#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 a

$('#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());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号