javascript .each() 클릭 관련 질문있습니다. 채택완료
예를들어
</p><p><style></p><p>.b{display:none;}</p><p></style></p><p><div class="a">1</div></p><p style="margin-left: 40px;"><div class="b">a</div></p><p style="font-size: 14.6667px;"><div class="a">1</div></p><p style="margin-left: 40px; font-size: 14.6667px;"><div class="b">a</div></p><p style="font-size: 14.6667px;"><div class="a">1</div></p><p style="margin-left: 40px; font-size: 14.6667px;"><div class="b">a</div></p><p style="font-size: 14.6667px;"><div class="a">1</div></p><p style="margin-left: 40px; font-size: 14.6667px;"><div class="b">a</div></p><p style="font-size: 14.6667px;"><div class="a">1</div></p><p style="margin-left: 40px; font-size: 14.6667px;"><div class="b">a</div></p><p style="margin-left: 40px; font-size: 14.6667px;">
이렇게 div가 구성되어있고, 첫번째 ".a" div 를 클릭하면 첫번째 ".b" div 가 보여지고 다시 클릭하면 hide 되는 스크립트를 짜려하는데
</p><p style="margin-left: 40px; font-size: 14.6667px;"><script></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;">$(document).ready(function(){</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>$('.a').each(function(i){</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>$(this).click(function(e){</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>$('.b').each(function(j){</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>$(this).eq(i).toggle(function(f){});</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>});</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>});</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;"><span class="Apple-tab-span" style="white-space:pre"> </span>});</span></p><p style="margin-left: 40px;"><span style="font-size: 14.6667px;">});</script></span> </p><p style="margin-left: 40px; font-size: 14.6667px;">
이렇게 하니까 반응이 없더라구요..
어떤식으로 수정해야하는지.. 부탁드립니다.
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
블랙캣77
8년 전
</p><p>$(".a").click(function(){</p><p style="margin-left: 40px;">var eq = $(".a").index($(this));</p><p style="margin-left: 40px;">$(".b").eq(eq).toggle("fast");</p><p>});</p><p>
테스트는 안해봤는데 한번 해보세요
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
�
8년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인전체 질문 목록
채택
채택
답변대기
답변대기
채택
채택
채택
채택
채택
채택
채택
채택
답변대기
채택
답변대기
답변대기
채택
채택
답변대기
채택
$(document).ready(function(){
$('.faq_q').each(function(i){
$(this).click(function(e){
$('.faq_a').eq(i).toggle('fast');
});
});
});
[/code]
자체 해결했습니당!! 감사합니다!!