2011-05-20 192 views
0

手風琴本身很容易切換,我不得不使用jQuery的UI手風琴,因爲可以輕鬆地添加書籤鏈接。在這一點上,我可以得到一個手風琴效果(從頭開始)切換,沒有可收藏的鏈接,或者獲得與用戶界面的書籤鏈接,並且不會切換。我希望能夠摺疊所有的手風琴內容,也就是說,如果您在觸發器展開後單擊該觸發器,第二次點擊就會關閉它。這裏是我有:如何使jQuery UI手風琴切換

$(function() { 
    //basic accordion settings 
    $('#accWrap').accordion({ 
     active: false, 
     alwaysOpen: false, 
     autoHeight: false, 
     navigation: true, 
     collapsable: true, 
     header: '.accButton' 
    }); 

    //attempt at toggling - does not work correctly 
    //$('.accButton').click(function() { 
    //$(this).next().toggle(); 
    //return false; 
    //}).next().hide(); 

    //bookmarkable function 
    $(".accButton").click(function(event){ 
     window.location.hash=this.hash; 
    }); 
}); 

任何人都看到任何明顯錯誤或我可以合併切換功能的方式?一如既往,我感謝幫助!

thx

+0

你是說你想同時擴展多個部分? – namuol 2011-05-20 13:13:37

+0

不,我希望能夠切換內容區域,也就是說,如果單擊「headerA」一次,它的內容就會顯示出來。再次點擊「headerA」並關閉內容。我已經設置好了,以便它不必打開一個,但我希望能夠雙擊(?)標題並關閉它。 – 2011-05-20 13:15:02

回答

0

嗨我不知道這是你想達到什麼。但是,這是我用什麼..

豈不等於從here

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> 
<script language="javascript"> 
$(document).ready(function() 
{ 
    //hide the all of the element with class msg_body 
    $(".msg_body").hide(); 
    //toggle the componenet with class msg_body 
    $(".hidebox_head").click(function() 
    { 
    $(this).next(".msg_body").slideToggle(600); 
    }); 
}); 
</script> 
</head> 
<body> 
<div class="msg_head"> 
click me</div> 
<div class="msg_body"> 
alksdjf löaskdjf ölaskjdöflkjas dlfkj asödlk 
</div> 
</body> 
</html> 
+0

夠簡單,但我需要可加入書籤的散列函數,這就是爲什麼我要使用UI。正如我所說的除了書籤/散列之外的切換功能很容易,它的組合它們給我的問題。 thx人。 – 2011-05-20 13:15:57

0

搶走看起來你拼錯的「可摺疊」。嘗試用「我」拼寫它「可摺疊」。

8

這是一個老話題,但因爲我一直在尋找自己的答案,並發現它在jQuery UI accordion doc

<script> 
    $(function() { 
     $("#accWrap").accordion({ 
      collapsible: true 
     }); 
    }); 
</script> 

「可摺疊」在你的代碼拼寫錯誤,它缺少了「我」。