javascript jquery 手风琴激活不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15640153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:30:33  来源:igfitidea点击:

jquery accordion activate does not work

javascriptjqueryhtmljquery-uiaccordion

提问by Glenn De Winter

I have a accordionlike this

我有一个accordion这样的

<div id="accordion">
    <h3 id="idname1">text</h3>
    <div>
        Text TEXT text
    </div>
    <h3 id="idname2">text</h3>
    <div>
        Text TEXT text
    </div>
    <h3 id="idname3">text</h3>
    <div>
        Text TEXT text
    </div>
</div>

Now i want the people to click a link (on the top of the page) and then that panel will open en people will see it now every time i call my function

现在我希望人们点击一个链接(在页面顶部),然后该面板将打开,每次我调用我的函数时人们都会看到它

$('.myclass').click(function() {
    // this is to open the right pannel 
    var getal = $(this).attr('id');
    alert(getal); // i get the right name

    $("#accordion").accordion('activate', 1);
});

my console gives me this error

我的控制台给了我这个错误

Error: no such method 'activate' for accordion widget instance

错误:手风琴小部件实例没有这种方法“激活”

i do not know what the problem is i have tried many different things but none worked.

我不知道问题是什么我尝试了很多不同的东西,但没有一个奏效。

回答by Ian

I think you are looking to open an accordion pane programmatically. If so, you want something like this:

我认为您希望以编程方式打开手风琴窗格。如果是这样,你想要这样的东西:

$("#accordion").accordion("option", "active", 1);

(assuming you're using the jQuery UI library)

(假设您使用的是 jQuery UI 库)

http://api.jqueryui.com/accordion/#option-active

http://api.jqueryui.com/accordion/#option-active

Note that this opens the second accordion pane, since the options accepts a 0-based integer. (0 is first, 1 is second, etc.). So just make sure you are passing the correct integer to the method call :)

请注意,这将打开第二个手风琴窗格,因为选项接受一个基于 0 的整数。(0 是第一个,1 是第二个,等等)。所以只要确保你将正确的整数传递给方法调用:)

The reason your code won't work is because the jQuery UI team just removed the activatemethod in v1.10 and specifically recommend using what I provided: http://jqueryui.com/upgrade-guide/1.10/#removed-activate-method-use-active-option

您的代码不起作用的原因是 jQuery UI 团队刚刚删除了activatev1.10 中的方法,并特别推荐使用我提供的方法:http: //jqueryui.com/upgrade-guide/1.10/#re​​moved-activate-method -use-active-option

回答by Lemonade

Activate it like this

像这样激活它

$( "#accordion" ).accordion( "option", "active", 0 );

To just enable/disable use the methods for that purpose.

要启用/禁用,请使用用于该目的的方法。

$("#accordion" ).accordion( "enable" );
$("#accordion" ).accordion( "disable" );

To access options of the accordion after first init use the options object.

要在第一次初始化后访问手风琴的选项,请使用选项对象。

$("#accordion").accordion( "option", "disabled", true ); // set
var x = $("#accordion").accordion( "option", "disabled"); // get

Look at the API http://api.jqueryui.com/accordion/

看API http://api.jqueryui.com/accordion/

回答by CoryDorning

This should work, however, it will not animate:

这应该有效,但是,它不会动画:

$('.myclass').click(function () {
         // this is to open the right pannel 
         var getal = $(this).attr('id');
         alert(getal); // i get the right name

         $("#accordion").accordion('option', 'active', 1);
     });

The method you are trying to use WAS in 1.9.x but was removed in 1.10.x http://api.jqueryui.com/accordion/#option-active

您尝试在 1.9.x 中使用 WAS 但在 1.10.x 中删除的方法 http://api.jqueryui.com/accordion/#option-active