를 얻기 위해 I DOM에 다음과 같은 구조를 가지고 :특정 하위 요소
을 :<div class="parent">
<div class="child0"></div>
<div class="child1"></div>
<div class="child2"></div>
<div class="child3"></div>
<div class="child4"></div>
<div class="child5"></div>
...
</div>
내가 자바 스크립트에서 수행하려고하는 특정 요소를 보여이 같은 다른 사람을 숨기는 것입니다
showItems(0,3,'.parent'); // show child 0,1,2
function showItems(offset,limit,component)
{
$(component).children().hide();
for(var i=offset;i<=(offset+limit);i++)
{
$(component+':nth-child('+i+')').show(); //!!! does not make them visible
}
}
어떤 아이디어가 있습니까?
감사합니다.
.children() 호출을 통해 직접 자식을 숨기고 있지만 우수한 점과 감독이 있으므로 실제로는 영향을주지 않아야합니다. –
나는 두 번째가 첫 번째보다 낫다는 것을 보지 못한다. 모든 자식 요소는'div '요소이며, 그것이 알려진 경우 간단히': nth-child'대신'div : nth-child '를 사용하는 것이 사실은 효율성이 떨어집니다. 요소가'div'이고': nth-child'인지를 검사합니다. –
이 경우에는 문제가되지는 않지만 부모 div에 더 많은 콘텐츠 또는 분리 기호 요소가있는 경우에는 도움이되지 않을까요? –