function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
$(function(){
var yourcolor = getCookie('color');
if(yourcolor){
if(yourcolor=="button1"){
} else if(yourcolor=="button2"){
$('.button1').removeClass('active');
$('.button2').addClass('active');
}
}
$('.button1, .button2').click(function(){
$('.button1, .button2').toggleClass('active');
if($('.button1').hasClass('active')){
var date = new Date(new Date().getTime() + 60 * 1000);
document.cookie = "color=button1; path=/; expires=" + date.toUTCString();
} else if($('.button2').hasClass('active')){
var date = new Date(new Date().getTime() + 60 * 1000);
document.cookie = "color=button2; path=/; expires=" + date.toUTCString();
}
});
});
Вот, но не работает.