0
다음을 사용하여 목록 항목의 첫 번째 요소를 대상으로 지정하는 데 문제가 있습니다.상위 항목의 첫 번째 요소를 대상으로 지정하십시오.
<li data-id="321">
<ul>
<li data-id="380">
<ul>
<li data-id="385"></li>
</ul>
</li>
<li data-id="382"></li>
</ul>
</li>
$(".drop .position").click(function() {
$this = $(this);
$targetID = $(".box-cont.active ").closest("li.box").data("id");
$childrenArray = new Array();
if ($target.find("ul:first").find("li").length > 0) {
$target.find("ul:first").find("li").each(function() {
$this = $(this);
$childrenArray.push($this.data("id"));
});
alert($childrenArray);
} else {
alert("no children");
}
난 단지 대신 (321) 내부의 최초 UL의 어린이를 대상으로 시도하고 난 단지 380와 382를 추가 할 때, 나는 배열에 380, 382, 및 385을 추가 해요
참조하는 요소 ('.box-cont' 또는'li.box' 등)는 예제 HTML에 없습니다. – moopet
'div'는 무엇입니까? 당신의 예제에서'div'가 보이지 않습니다. –
'$ target.find ("ul : first> li"). 각 (function()'(또는 더 나은 :'map()') 보다 완전한 HTML 샘플을 통해이 사실을 확인할 수 있습니다. –