Jquery - asp.net code accordion state behind

Can someone tell me how to keep the accordion jquery active state bar when changing pages. Ideally, I would like to change the code, but really happy just to make it work.

development in asp.net 3.5

Hope this helps

thanks

+3
source share
4 answers

An example is here . If you select one of the accordion headings, then refresh the page on which you clicked the last consent bar, by default

. cookie . , .

-

//get persisted active accoridan index
var activeIndex  = $.cookie('accordianActiveIndex');

//guard code here to check you have a valid activeIndex...

$('.selector').accordion({
       active: activeIndex,
       change: function(event, ui) { 
           //set cookie here to new active header (index)
           $.cookie('accordianActiveIndex', ui.newHeader.prevAll().length)
      }
});
+3

, cookie jQuery UI Accordion, ,

+2

Accordion UI cookie.js:

()

var accordion = $("#accordion");
var index = $.cookie("accordion");
var active;
if (index !== null) {
    active = accordion.find("h3:eq(" + index + ")");
} else {
    active = 0
}
accordion.accordion({
    header: "h3",
    event: "click hoverintent",
    active: active,
    change: function(event, ui) {
        var index = $(this).find("h3").index ( ui.newHeader[0] );
        $.cookie("accordion", index, {
            path: "/"
        });
    },
    autoHeight: false
});
+1

$( ".selector" ).accordion({ navigation: true });

0

Source: https://habr.com/ru/post/1715896/


All Articles