简体   繁体   中英

Best way to find all input elements inside a form using jQuery

I need to find all form elements inside inside a form and trigger a flag on change in the value. Currently I am using the method below. I am not sure if this works or not. But It surely works for: .find('input[type=text])

$('#form').find('input[type=text], input[type=radio], input[type=checkbox], select, textarea').each(function(){
  $(this).change(function(){
    if( change !== 1 ) change = 1;
  });
})

Now I have added multiple elements with the comma. Will this work and is this the best way to do this.

Appreciate all the help.

Thanks!

Try this:

$('#form').find(':input').each(function(){
  $(this).change(function(){
    if( change !== 1 ) change = 1;
  });
})

Check the doc @:

http://api.jquery.com/input-selector/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM