jQuery UI手风琴避免关闭项目wnen单击另一项 [英] jquery ui accordion avoid closing item wnen clicking on another one

查看:87
本文介绍了jQuery UI手风琴避免关闭项目wnen单击另一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从现有的小提琴开始,我创建了以下示例: http://jsfiddle.net/2DaR6/90 /

starting from existing fiddle, I've created this sample: 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>

这是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 );
    });
});​

如果我单击第1节,手风琴可以正确打开,但是我希望单击其他项,则以前打开的项不会关闭.我如何获得这种行为? 谢谢

If I click on Section 1, accordion correctly opens, but I want that clicking on other items, previously opened items won't close. How can I obtain this behaviour? Thanks

推荐答案

您不应将jquery手风琴用于这种目的. 但是,它相对容易覆盖任何元素事件的行为.初始化手风琴后,您只需要将click handler覆盖到相应的元素即可.

You should not use jquery accordion for this kind of purpose. However, its relatively easy to override any element events behaviour. When accordion is initialized, you just have to override click handler to corresponding elements.

在您的情况下,这给出了以下信息:

In your case, this giving something like this:

$('#accordion .accClicked')
        .off('click')
    .click(function(){
        $(this).next().toggle('fast');
    });​

查看正在运行的 jsFiddle

这篇关于jQuery UI手风琴避免关闭项目wnen单击另一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆