【问题标题】:Jquery Cookies IssueJquery Cookie 问题
【发布时间】: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


【解决方案1】:

您似乎缺少一些分号:

switch (intImage) {

 case 1:
    intImage = 2;
    $('.giftarrow').attr('src', 'http://www.gracecole.co.uk/shop/skin/frontend/default/default/images/left-arrow.png');
    jQuery.cookie('catCookie', 'left');
    return(false);

 case 2:
    intImage = 1;
    $('.giftarrow').attr('src','http://www.gracecole.co.uk/shop/skin/frontend/default/default/images/down-arrow.png');
    jQuery.cookie('catCookie', 'down');
    return(false);
 }

【讨论】:

    猜你喜欢
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多