jquery ui accordion避免关闭项目wnen点击另一个

Fra*_*nky 3 javascript jquery jquery-ui accordion

从现有的小提琴开始,我创建了这个样本:http://jsfiddle.net/2DaR6/90/

这是html代码:

<div id="accordion">
  <h3 id="header1" class="accClicked"><a href="#">Section 1</a></h3>
    <div> Good Morning Stackoverflow</div>
  <h3 id="header2" class="accClicked"><a href="#">Section 2</a></h3>
    <div>Buongiorno Stackoverflow</div>
  <h3 id="header3" class="accClicked"><a href="#">Section 3</a></h3>
    <div>Bonjour Stackoverflow</div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是js代码:

$(function() {
    var icons = {
        header: "ui-icon-circle-arrow-e",
        headerSelected: "ui-icon-circle-arrow-s"
    };
    $( "#accordion" ).accordion({
        icons: icons,
        collapsible: true
    });
    $( "#header1" ).click(function() {
        $( "#accordion" ).accordion( "option", "icons", false );
    }, function() {
        $( "#accordion" ).accordion( "option", "icons", icons );
    });
});?
Run Code Online (Sandbox Code Playgroud)

如果我点击第1部分,手风琴正确打开,但我希望点击其他项目,之前打开的项目将不会关闭.我怎样才能获得这种行为?谢谢

A. *_*lff 9

你不应该使用jquery手风琴来达到这种目的.但是,它相对容易覆盖任何元素事件行为.初始化accordion时,您只需将click handler重写为相应的元素.

在你的情况下,这给出了这样的东西:

$('#accordion .accClicked')
        .off('click')
    .click(function(){
        $(this).next().toggle('fast');
    });?
Run Code Online (Sandbox Code Playgroud)

见工作jsFiddle