jquery - 由父级返回到不同的子级 JQuery
问题描述
这是我的带有不同数量复选框的动态页面的代码。我想知道的是我设置的“.parent().children()”属性是否可行。我不断返回 [Object Object]。你能帮忙的话,我会很高兴。
<div>
<input name='input1' id='src-1' value = 'input1' type='checkbox'/><br />
<input name='depnum1' id='depnum-1' value = '' type='text'/><br />
<input name='depdate1' id='depdate-1' value = '' type='text'/>
</div>
<script>
$(document).ready(function() {
$("#SubDeposit").click(function(){
$('input[type=checkbox]').each(function (){
if($(this).prop('checked')) {
//variables
var fileLocation = $(this).attr('id');
var fileLocation = fileLocation.substring(4);
alert(fileLocation);
//Variables for inputs that relate to the chekcbox
depnum = ($(this).parent().children('depnum-'+fileLocation));
depdate = ($(this).parent().children("depdate-"+fileLocation));
alert(depnum);
alert(depdate);
console.log(depnum);
console.log(depdate);
}
});
});
});
</script>
解决方案
我认为问题在于您的选择器。您想找到具有 id=some 值的元素。在这种情况下, id 的选择器是"#text"
如此,正确的 jquery 调用将是
depnum = ($(this).parent().find('#depnum-'+fileLocation));
depdate = ($(this).parent().find("#depdate-"+fileLocation));
推荐阅读
- javascript - jquery .prop(checked,true) 值未反映在调用的方法中
- sql-server - 用零替换列中的字符串
- asp.net-core - 每个 WaterfallStep 的自定义帮助消息
- xml - xsd 忽略元素的顺序和 maxOccurs 未绑定
- firebase - kotlin room livedata 列表值始终为空
- python - 收到错误“客户端具有本地且不可腌制的非平凡状态。” 在 python 中使用 BigQuery 客户端库时?
- css - list-style-type 字符串值工作正常,即使它不是有效值
- kubernetes-helm - Helm Chart ServicePort 和 Ingress with Https
- selenium - Selenium - 页面对象模型与定义公共静态最终
- python - 在对最大成对乘积进行压力测试时,在长缩放器中遇到溢出