2014-07-14 3 views
1

좋아이 어딘가에 내가의 라인을 따라 뭔가가 필요 거기에 분명 내 자바 스크립트플러스와 아코디언에 마이너스 내가 <a href="http://jsfiddle.net/rW3KU/1/" rel="nofollow">here</a></p> <p>볼 수있는 작업 아코디언, 그래서

$(document).ready(function ($) { 
    $('#accordion').find('.accordion-toggle').click(function() { 

     //Expand 
     $(this).next().slideDown('fast'); 
     $(this).children(".plusminus").text('-'); 

     //hide other panels 
     $(".accordion-content").not($(this).next()).slideUp('fast'); 

    }); 
}); 

입니다 :

  $(this).next().slideUp('fast'); 
      $(this).children(".plusminus").text('+'); 

내용 상자를 닫고 + 기호로 다시 변경하지만 어떻게해야하는지 잘 모릅니다. 어떤 도움이 필요합니까?

+0

힌트 같은 클래스가 : 당신은이'+'또는'-' 처음이 있는지 여부를 확인하기 위해 기호를 확인해야합니다. –

+0

CSS를 사용하여': after' 또는': before' 콘텐츠를 지정하십시오. – Blazemonger

+1

바이올린 업데이트 : http://jsfiddle.net/rW3KU/2/ –

답변

4

셀렉터에서이 작업을 수행하는 방법에는 여러 가지가 있으며, 가장 효율적인 것이 무엇인지 잘 모르겠지만 부모를 확보하고 형제를 선택하고 표시기를 찾는 것이 한 가지 방법입니다. 그렇다면 쉽게 설정할 수 있습니다. 여기에 기존의 코드를 사용하여이 방법 :

demo

$(document).ready(function ($) { 
    $('#accordion').find('.accordion-toggle').click(function() { 

     //Expand 
     $(this).next().slideDown('fast'); 
     $(this).parent().siblings().find(".plusminus").text('+'); 
     $(this).children(".plusminus").text('-'); 

     //hide other panels 
     $(".accordion-content").not($(this).next()).slideUp('fast'); 

    }); 
}); 

편집 :

훨씬 선호하는 방법 (제 생각에 적어도) 의사 요소 클래스를 사용하는 것입니다.

$(document).ready(function ($) { 
    $('#accordion').find('.accordion-toggle').click(function() { 

     //Expand 
     $(this).next().slideDown('fast'); 
     $(this) 
      .closest('.accordion-wrap').addClass('active') 
      .siblings().removeClass('active'); 

     //hide other panels 
     $(".accordion-content").not($(this).next()).slideUp('fast'); 

    }); 
}); 

demo

는 너무

.accordion-wrap .accordion-toggle::after { 
    content:'\000a0-'; 
} 
.accordion-wrap.active .accordion-toggle::after { 
    content:'\000a0+'; 
} 
+0

잘 작동합니다. 감사합니다! 어쨌든 마이너스가 토글을 클릭하여 닫을 때 플러스로 되돌아 가도록할까요? 다른 토글을 클릭했을 때뿐만 아니라? 분명히 slideDown을 slideToggle로 바꿔서 닫을 수 있습니다 ... – JoshuaBrand

+0

@JoshuaBrand 나는 거기에 그 기능을 보지 못했지만 그것이 열렸는지를 결정한 후에 클릭하면 제거 할 수 있습니다. –

+0

이 솔루션으로 전체 아코디언을 닫을 수는 없습니다. –