2011-02-09 68 views
0

如果可能的話,需要幫助。我覺得我很接近,不能完全弄明白。基本上如標題所示,我需要有幾個勾選框,如果勾選了一個框,手風琴效果將會啓動並顯示一個textarea。jQuery Accordian需要用勾號框打開/關閉,並且在勾選框時保持打開狀態

如果選中該框,我需要手風琴保持打開狀態。

如果盒子沒有打勾,我需要手風琴關閉。

HTML ` 堅實的基礎(車輪)

你在哪裏完全符合沒有進一步的評論是必要的。如果您尚未完全符合要求,請提供更多信息。

     <div class="CheckButton two"> 
          <label><input type="checkbox" />Getting to Grips With Governance (The Wheel)</label>       
         </div><!--checkButton--> 
         <div class="TextareaAccordion two"> 
          <p><span class="helptext">Where you are fully compliant no further comment is necessary. Where you are not yet fully compliant please provide more information.</span></p> 
          <textarea name="" cols="10" rows="3" id="explanatorytext"></textarea> 
         </div> 

         <div class="CheckButton three"> 
          <label><input type="checkbox" />Reducing the Risk (The Wheel)</label>      
         </div><!--checkButton--> 
         <div class="TextareaAccordion three"> 
          <p><span class="helptext">Where you are fully compliant no further comment is necessary. Where you are not yet fully compliant please provide more information.</span></p> 
          <textarea name="" cols="10" rows="3" id="explanatorytext"></textarea> 
         </div>` 

JS

<script type="text/javascript"> 
        $(document).ready(function() { 
         //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING) 
         $('.CheckButton.one, .CheckButton.two, .CheckButton.three, .CheckButton.four, .CheckButton.five, .CheckButton.six, .CheckButton.seven, .CheckButton.eight, .CheckButton.nine').click(function() { 

         if($(this).next().is(':hidden') == true) { 
         //ADD THE ON CLASS TO THE BUTTON 
         $(this).addClass('on'); 
         //OPEN THE SLIDE 
         $(this).next().slideDown('normal'); 
         } 

        }); 




        /**CLOSES ALL S ON PAGE LOAD**/ 
        $('.TextareaAccordion.one, .TextareaAccordion.two, .TextareaAccordion.three, .TextareaAccordion.four, .TextareaAccordion.five, .TextareaAccordion.six, .TextareaAccordion.seven, .TextareaAccordion.eight, .TextareaAccordion.nine').hide();}); 
       </script> 

提前感謝!

回答

0

首先,我想借此出:

$('.TextareaAccordion.one, .TextareaAccordion.two, .TextareaAccordion.three, .TextareaAccordion.four, .TextareaAccordion.five, .TextareaAccordion.six, .TextareaAccordion.seven, .TextareaAccordion.eight, .TextareaAccordion.nine').hide(); 

我只想用CSS來隱藏這些div標籤。其次,你不必單獨引用它們中的每一個,$('.TextareaAccordion').hide();就足夠了。

這是我的解決方案:http://jsbin.com/egude4/22/edit

+0

嗨Anriëtte,謝謝你的回覆。好吧,我想我明白了。基本上每個帶隱藏文本區域的複選框必須是它自己的獨立手風琴。這是因爲如果打開一個,然後單擊另一個,則會關閉前一個。如果每個手風琴都是自己獨立的手風琴,那麼它們都可以開放,或者如果需要的話都可以關閉。 – davejfox 2011-02-09 14:10:18