0

问题:

我将如何使用函数以编程方式控制应该打开哪个 jquery-ui“手风琴”面板?

感谢您的任何帮助/指导!

注意:下面是我尝试使用以下函数打开手风琴面板的一些示例。

--不幸的是,这些都不起作用。

(jquery 1.8.0, jquery-ui 1.8.23)

1.

    $('#abc').accordion(
    {
        active: false,
        icons: false,
        collapsible: true,
        animated: true,
        navigation: true,
        event: "click keyup",
        create: function(event, ui) {      
            $("#abc").accordion( "option" , "active" , getAindex() );
        }            
    }); 

2.

    $('#abc').accordion(
    {
        icons: false,
        active: function(event, ui) {   
            return getAindex();
        },
        collapsible: true,
        animated: true,
        navigation: true,
        event: "click keyup"
    });     

3.

    $('#abc').accordion(
    {
        icons: false,
        active: getAindex(),
        collapsible: true,
        animated: true,
        navigation: true,
        event: "click keyup"
    });     

“getAindex()”函数看起来像这样......

    function getAindex()
    {
        var idx = 0;
        var jqXHR2 = $.ajax({
            type: "GET",
            url: 'getAindex',
            async: false,
            cache: false
        })
        .done(function(data, textStatus, jqXHR)
        {
            idx = data
            $("#aindex").val(idx);
        })
        .fail(function(jqXHR, textStatus, errorThrown)
        {
            alert("FAIL:  getAindex: jqXHR:" + jqXHR + "...textStatus:" + textStatus + "...errorThrown:" + errorThrown");
        });

        return idx;
    }

HTML看起来像这样......

    <div id="abc">
        <h3>tabA</h3>
        <div>
            <div>
                <span>tabA-content1</span>
            </div>
            <div>
                <span>tabA-content2</span>
            </div>              
        </div>
        <h3>tabB</h3>
        <div>
            <div>
                <span>tabB-content1</span>
            </div>
            <div>
                <span>tabB-content2</span>
            </div>              
        </div>
        <h3>tabC</h3>
        <div>
            <div>
                <span>tabC-content1</span>
            </div>
            <div>
                <span>tabC-content2</span>
            </div>              
        </div>
    </div>      

“固定”手风琴定义......

    $('#abc').accordion(
    {
        active: getAindex(),
        icons: false,
        collapsible: true,
        animated: true,
        navigation: true,
        event: "click keyup",
        change: function(event, ui) {              
            if (ui.options.active !== false)
            {
                setAindex(ui.options.active);
            }
        }          
    }); 

“固定” Aindex() 函数...

    function getAindex()
    {
        var idx = 0;
        var jqXHR2 = $.ajax({
            type: "GET",
            url: 'getAindex',
            async: false,
            cache: false
        })
        .done(function(data, textStatus, jqXHR)
        {
            idx = parseInt(data);    //  <== NOTE:  added this...
            $("#aindex").val(idx);   
        })
        .fail(function(jqXHR, textStatus, errorThrown)
        {
            alert("getAindex() - FAIL:  jqXHR:" + jqXHR + "...textStatus:" + textStatus + "...errorThrown:" + errorThrown);
        });

        return idx
    }
4

0 回答 0