我在网页上使用 jquery 选项卡,当刷新页面时,它会丢失我曾经使用过的选项卡并返回到第一个选项卡。
有谁遇到过这个问题并知道如何解决它?
和其他人一样,我也在 jQueryUI 1.10 中为 ui-tabs cookie 历史而苦苦挣扎。
感谢 Harry 的解决方案和我在下面的代码中引用的其他一些在线文档,我现在有了一个有效的非 cookie 解决方案!我能够在 Firefox 18.0.1 和 IE 9.0.12 中进行测试。根据我的资源,Chrome、Firefox、Safari 和 IE8 及以上版本支持会话存储。
$(function() {
// jQueryUI 1.10 and HTML5 ready
// http://jqueryui.com/upgrade-guide/1.10/#removed-cookie-option
// Documentation
// http://api.jqueryui.com/tabs/#option-active
// http://api.jqueryui.com/tabs/#event-activate
// http://balaarjunan.wordpress.com/2010/11/10/html5-session-storage-key-things-to-consider/
//
// Define friendly index name
var index = 'key';
// Define friendly data store name
var dataStore = window.sessionStorage;
// Start magic!
try {
// getter: Fetch previous value
var oldIndex = dataStore.getItem(index);
} catch(e) {
// getter: Always default to first tab in error state
var oldIndex = 0;
}
$('#tabs').tabs({
// The zero-based index of the panel that is active (open)
active : oldIndex,
// Triggered after a tab has been activated
activate : function( event, ui ){
// Get future value
var newIndex = ui.newTab.parent().children().index(ui.newTab);
// Set future value
dataStore.setItem( index, newIndex )
}
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)