0
시작시 한 서랍 만 열어두기를 원합니다. 현재 모든 서랍이 열려 있습니다.시작시 jQuery로 한 서랍 만 표시 할 수 없습니다.
몸에 jQuery code
$(document).ready(function() {
// hide all ULs inside LI.drawer except the first one
$('LI.drawer UL:not(:first)').hide();
// apply the open class
$('li.drawer:first ul').addClass('open');
$('h2.drawer-handle').click(function() {
// hide the currently visible drawer contents
$('li.drawer ul:visible').hide();
// remove the open class from the currently open drawer
$('h2.open').removeClass('open');
// show the associated drawer content to 'this' (this is the current H2 element)
// since the drawer content is the next element after the clicked H2, we find
// it and show it using this:
$(this).next().show();
// set a class indicating on the H2 that the drawer is open
$(this).addClass('open');
});
});
html로
<ul class="drawers">
<li class="drawer">
<h2 class="drawer-handle open">Contact</h2>
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
<li class="drawer">
<h2 class="drawer-handle">papers</h2>
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
</ul>
어떻게 하나 개의 서랍을 표시하고 시작시 나머지를 숨길 수 있습니까?
지적 해 주셔서 감사합니다. –
같은 문제가 여전히 발생하는 것 같습니다. –
같은 문제가 여전히 존재하지만 hide() 줄에 있다고 생각합니다. 현재 첫 번째 줄에는 "모든 LI.drawer 내에서 첫 번째 것이 아닌 모든 UL 숨기기"가 표시되어 아무 것도 숨기지 않습니다. 나는 당신이 'LI.drawer : not (: first UL)'를 원한다고 생각합니다. –