【发布时间】:2013-11-03 19:19:33
【问题描述】:
如何通过检查用户 cookie 来更改 jQuery .hover() 中的函数?
现在代码在网站首次加载时有效,但是当 cookie 更新(通过 javascript)时,.hover() 不会切换,除非重新加载页面:
var SkinChk = getCookie('skincookie');
$('.fadeMenu').hover(function(){
if (SkinChk == 'Alternative') {
// Alternative Skin
$(this).stop().animate({ backgroundColor:'rgb(66, 137,170)', color:'#F7F9F4'},500);
} else {
// Default Skin
$(this).stop().animate({ backgroundColor:'rgb(255,165,0)', color:'#FFFFFF'},500);
}
}, function(){
if (SkinChk == 'Alternative') {
// Alternative Skin
$(this).stop().animate({ backgroundColor:'rgb(247, 249, 244)', color:'#1F262A'},500);
} else {
// Default Skin
$(this).stop().animate({ backgroundColor:'rgb(201,224,179)', color:'#333333'},500);
}
});
var SkinChk = getCookie('skincookie'); 引用了一个有效的 javascript 函数,为了简洁起见,我没有发布。它返回 cookie 值。
【问题讨论】:
-
你应该添加
getCookie()的代码
标签: javascript jquery css jquery-ui cookies