【发布时间】:2011-07-04 16:33:41
【问题描述】:
我正在尝试使用 jquery cookie 在页面加载之间存储树形菜单的状态,由于某种原因,下面的代码似乎没有在 switch 语句中创建 cookie。在 switch 语句之外使用 cookie 代码可以正常工作。我对 JS 不太了解,所以这可能是我的开关的一个简单问题,
intImage = 2;
var catCookie = jQuery.cookie('catCookie');
if(catCookie == 'left')
{
intImage = 1;
};
if(catCookie == 'down')
{
intImage = 2;
};
function swapImage() {
switch (intImage) {
case 1:
intImage = 2
document.getElementById(".giftarrow").src = "http://www.domain.com/left-arrow.png";
jQuery.cookie('catCookie', 'left')
return(false);
case 2:
intImage = 1
document.getElementById(".giftarrow").src = "http://www.domain.com/down-arrow.png";
jQuery.cookie('catCookie', 'down')
return(false);
}
}
非常感谢任何帮助。
【问题讨论】:
-
既然你已经在使用jquery了,为什么要使用
document.getElementById(".giftarrow")而不是$("giftarrow)呢?后者不会更酷吗? -
我只是打算在原始版本中使用标准 js,一旦它工作就会清理语法。
标签: javascript jquery jquery-plugins cookies