jQuery UI Accordion + Cookies - 默认关闭? [英] jQuery UI Accordion + Cookies - Closed by Default?
本文介绍了jQuery UI Accordion + Cookies - 默认关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery UI Accordion,我成功地使用cookie来记住刷新页面时的最后一个活动状态 - 但是我无法:
With the jQuery UI Accordion, I am successful in the use of cookies to remember the last active state when refreshing the page- however I am unable to:
-
设置为首次访问时折叠
set to collapsed on first visit
如果用户在打开后手动折叠了,请记住Cookie
have cookie remember if the user has manually collapsed after opening
我试图在有效选项上尝试使用条件语句创建一个函数,但是没有成功。
I've tried to attempt creating a function with conditional statement on the "active" option but was unsuccessful.
jQuery(document).ready(function(){
var act = 0;
$( "#accordion" ).accordion({
create: function(event, ui) {
//get index in cookie on accordion create event
if($.cookie('saved_index') != null){
act = parseInt($.cookie('saved_index'));
}
},
change: function(event, ui) {
//set cookie for current index on change event
$.cookie('saved_index', null);
$.cookie('saved_index', ui.options.active);
},
active:parseInt($.cookie('saved_index')),
collapsible: true
});
});
推荐答案
jQuery(document).ready(function(){
$( "#accordion" ).accordion({
change: function(event, ui) {
$.cookie('saved_index', ui.options.active !== false ? ui.options.active : null);
},
active: $.cookie('saved_index') != null ? parseInt($.cookie('saved_index')) : false,
collapsible: true
});
});
ps:如果您将网页打开为本地文件,则Google Chrome不接受Cookie。
ps: Google Chrome does not accept cookies if you open your page as a local file.
这篇关于jQuery UI Accordion + Cookies - 默认关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文