1
我創建了一個帶有選擇輸入的頁面來更改正在使用的jQuery UI主題。當主題被改變時,它被存儲在一個cookie中。加載頁面時,如果cookie存在,主題將被恢復,否則會加載默認主題。瀏覽器 - 強制重新加載刪除Cookie?
當我使用F5刷新頁面時,我的代碼確實有效,但如果我使用Ctrl + F5強制完成重新加載,則不會。這是我的代碼中的問題,還是它的正常效果?
這裏是我的代碼,如果需要的話:
(function($) {
$(function() {
var $themeSelect = $('#themeSelect');
var initialTheme = $.cookie('theme');
$themeSelect.on('change', function() {
var dir = 'jQueryUI/css/' + $themeSelect.val();
$('#uiThemeA').attr('href', dir + '/jquery-ui.min.css');
$('#uiThemeB').attr('href', dir + '/jquery.ui.theme.css');
$.cookie('theme', $themeSelect.val());
});
if(initialTheme !== undefined) {
$themeSelect.children().each(function(index, element) {
var $element = $(element);
if($element.attr('selected')) {
$element.removeAttr('selected');
}
if($element.attr('value') === initialTheme) {
$element.attr('selected');
}
}).trigger('change');
} else {
$.cookie('theme', $themeSelect.val());
}
});
})(jQuery);
感謝您的幫助!