遍历嵌套到组和节中的一组输入
iterate through a a set of input nested into groups and sections
我想遍历嵌套在组和节中的一组输入,目标是在每个组和节中执行验证
<script src="jquery/jquery.js"></script>
<div id="groupA" class="preGroups">
<div id="section-A1">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
<div id="section-A2">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
<div id="section-A3">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
<div id="section-A4">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
</div>
<div id="groupB" class="preGroups">
<div id="section-B1">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
<div id="section-B2">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
<div id="section-B3">
<input name="SRPR1" type="text">
<input name="SRPR2" type="text">
</div>
</div>
<script>
// capture all groups
groups = $('div#[id^=group]');
console.log(groups);
// iterate through each group in groups
$.each(groups, function(key, group) {
console.log(group);
// iterate through each section in group
sections = $('div#[id^=section]');
$.each(sections, function(key, section) {
console.log(section);
// iterate inputs in each group
// more code goes here
/// console.log(input.name + " " + input.value);
});
});
看起来你可能需要sections = $(group).find('div#[id^=section]');
而不是sections = $('div#[id^=section]');
编辑
完整代码:
groups = $('div[id^="group"]');
//console.log(groups);
// iterate through each group in groups
$.each(groups, function(key, group) {
//console.log(group);
// iterate through each section in group
sections = $(group).find('div[id^="section"]');
$.each(sections, function(key, section) {
//console.log(section);
var inputs = $(section).find("input");
// iterate inputs in each group
// more code goes here
inputs.each(function(){
console.log(this.name + " " + this.value);
})
/// console.log(input.name + " " + input.value);
});
});
演示
相关文章:
- 如何在一个表的输入中搜索一组特定的值,而不是另一个表's id(s)值以添加css
- 使用一组大的输入框进行表单验证
- 尝试使用 jQuery 序列化() 一组输入字段
- 组合功能以使用 Jquery 在一组单选按钮中显示输入字段和单选按钮
- 对两个不同的输入重复一组摩卡测试
- Google 表格自定义函数的多个数组输入,可将一个数组除以另一个数组
- 当输入发生更改时,从一组输入中删除内容
- jquery表单验证需要一组输入中的一个,并要求输入是整数
- 如果选中复选框,则将一组输入字段设置为禁用
- 在交互方面,不要允许文本输入中的第一个字符是一个空格或一组空格
- 将输入字段中的字符限制为一组字符
- 基于一个值对一组输入使用ng-disabled
- 如何使用html input required属性将一组输入设置为required ?
- 如何获取输入字段,根据一组规则过滤输入并应用于另一个字段
- 检查我的用户输入的是一组长度的数字
- 如何使用jquery防止用户取消一组复选框输入中的所有复选
- jquery的一组输入值乘以dynamic(另一个输入)
- 遍历嵌套到组和节中的一组输入
- 如何在填写现有字段后在表单中添加一组输入字段
- 在js表单上,如何隐藏/显示单选按钮(一组3个按钮中的一个或两个)取决于在上面字段中输入的数字的值