我期待值1和2,但它返回null。知道为什么会这样吗?
$(function() {
$('.agent_rows').each(function() {
console.log($(this).find('input[name="associatedAgentId"]').val())
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="1">
</div>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="2">
</div>
答案 0 :(得分:1)
您设置的属性不正确。它应该是value
而不是属性中的val
:
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="1">
</div>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="2">
</div>
答案 1 :(得分:0)
应该是value
而不是val
:
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="1">
</div>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="2">
</div>
工作代码段
$(function() {
$('.agent_rows').each(function() {
console.log($(this).find('input[name="associatedAgentId"]').val())
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="1">
</div>
<div class="agent_rows">
<input type="hidden" name="associatedAgentId" value="2">
</div>