开发者

Jquery Cookies Issue

开发者 https://www.devze.com 2023-03-17 15:36 出处:网络
I\'m trying to use jquery cookies to store the state of a tree menu between page loads, for some reason the below code does not seem to create a cookie inside the switch statement. Using the cookie co

I'm trying to use jquery cookies to store the state of a tree menu between page loads, for some reason the below code does not seem to create a cookie inside the switch statement. Using the cookie code outside of the switch statement works fine. I'm not too great with JS so it could be a simple issue with my switch,

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.d开发者_开发技巧omain.com/down-arrow.png";
 jQuery.cookie('catCookie', 'down')
 return(false);
 }
}

any help is greatly appreciated.


You seem to be missing some semicolons:

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);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消