Javascript 使用 jQuery 在表单中查找所有输入元素的最佳方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4847766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to find all input elements inside a form using jQuery
提问by Aayush
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])
我需要在表单内找到所有表单元素,并在值发生变化时触发一个标志。目前我正在使用下面的方法。我不确定这是否有效。但它肯定适用于:.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!
谢谢!
回答by Chandu
Try this:
尝试这个:
$('#form').find(':input').each(function(){
$(this).change(function(){
if( change !== 1 ) change = 1;
});
})
Check the doc @:
检查文档@: