如何解决使用JQuery进行迭代时,从每个父值中获取每个子值
我想找到每个子输入的值,这些值对所有选中的复选框输入都进行了迭代。因此,对于我要迭代的复选框的每个值,我想查找同时隐藏的每个输入的值 如下所示:
function submitBTN() {
var input_parent_grouped = [];
var input_child_grouped = [];
$.each($("input[name='input_parent']:checked"),function(){
input_parent_grouped.push($(this).val());
input_child_grouped.push($(this).children(".input_child").val());
});
console.log(input_parent_grouped);
console.log(input_child_grouped);
}
<div>
<input type="checkBox" class="input_parent" name="input_parent" value="1">
<input type="hidden" class="input_child" name="input_child" value="1">
<input type="checkBox" class="input_parent" name="input_parent" value="2">
<input type="hidden" class="input_child" name="input_child" value="1">
<input type="checkBox" class="input_parent" name="input_parent" value="3">
<input type="hidden" class="input_child" name="input_child" value="2">
<button type="button" class="btn btn-info" onclick="submitBTN()">Save</button>
</div>
这样,input_child_grouped的所有值都未定义。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。