这让我很头疼,我似乎找不到我需要找到的 dom 元素,我尝试过下一个/最近的/查找,但似乎找不到 div。该代码非常不言自明。
行 $(this).parent().siblings("div").find("#accounts").slideToggle(500); 不会让我得到称为帐户的 div。
<div data-bind="foreach: Households " class="householdRow">
<div class="actions item"><img id="toggle" src="~/Images/toggle.png"/></div>
<div class="item" data-bind="text: HouseholdId"></div>
<div class="item" data-bind="text: Name"></div>
<div class="item">IACodes</div>
<div class="item">Date</div>
<div class="numberItem item">T12</div>
<div class="numberItem item">AUA</div>
<div class="item" data-bind="text: Segmentation.Name"></div>
<div class="actions item"></div>
<div id="accounts" data-bind="foreach: Accounts">
<div class="accountRow">
<div class="item" data-bind="text: xxx"></div>
<div class="item" data-bind="text: xxx"></div>
<div class="item" data-bind="text: xxx"></div>
<div class="item" data-bind="dateFormat: xxx"></div>
<div class="numberItem item" data-bind="text: xxx"></div>
<div class="numberItem item" data-bind="text: xxx"></div>
<div class="item"></div>
<div class="actions item"><img id="delete" src="~/Images/delete.png"/></div>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
...
$(document).on("click", "#toggle", function () {
//$(this).next("#accounts").slideToggle(500);
$(this).parent().siblings("div").find("#accounts").slideToggle(500);
});
});
</script>