如何通过jQuery找到表单中的所有输入/ textareas?我知道你可以使用.children然后.each,但我正在构建一个验证类,我不知道是否有一些输入有一个包装器,因为它应该适用于我的所有表单.
$('input[type=submit]').click(function(){
$(this).closest('form').children('input,textarea').each(function(){
// do something with the input/textarea
)};
});
Run Code Online (Sandbox Code Playgroud)
这是有效的,但前提是输入正好在表格之后......
使用.find()得到一个给定的选择匹配的所有后代:
$('input[type=submit]').click(function() {
$(this).closest('form').find('input,textarea').each(function() {
/* Do something with the input/textarea */
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10264 次 |
| 最近记录: |