0
$(document).ready(function(){

   var lastsettings = $.cookie('location');

    if(lastsettings == "blue"){
    $('fieldset').css('background-color', 'blue');
    $('fieldset').css('margin-top', '0px');
        $('fieldset').css('margin-left', '0px');
   }
    else if(lastsettings == "red"){
        $('fieldset').css('background-color', 'red');
        $('fieldset').css('margin-top', '0px');
        $('fieldset').css('margin-right', '0px');
    }
    else if(lastsettings == "yellow"){
        $('fieldset').css('background-color', 'yellow');
        $('fieldset').css('margin-top', '240px');
        $('fieldset').css('margin-left', '0px');
    }
    else if(lastsettings == "green"){
        $('fieldset').css('background-color', 'green');
        $('fieldset').css('margin-top', '240px');
        $('fieldset').css('margin-right', '0px');
    }

$('select').change(function(){
    $('select option:selected').each(function(){
        position = this.text;

        $('fieldset').css('margin', 'auto');

        if(position == "Top Left"){
            $('fieldset').css('background-color', 'blue');
            $('fieldset').css('margin-top', '0px');
            $('fieldset').css('margin-left', '0px');
            $.cookie('position', 'blue');
        }
        else if(position == "Top Right"){
            $('fieldset').css('background-color', 'red');
            $('fieldset').css('margin-top', '0px');
            $('fieldset').css('margin-right', '0px');
            $.cookie('position', 'red');
        }
        else if(position == "Bottom Left"){
            $('fieldset').css('background-color', 'yellow');
            $('fieldset').css('margin-top', '240px');
            $('fieldset').css('margin-left', '0px');
            $.cookie('position', 'yellow');
        }
        else if(position == "Bottom Right"){
            $('fieldset').css('background-color', 'green');
            $('fieldset').css('margin-top', '240px');
            $('fieldset').css('margin-right', '0px');
            $.cookie('position', 'green');
        }
        else{
            $('fieldset').css('background-color', 'white');
            $('fieldset').css('margin', 'auto');
            $('fieldset').css('margin-top', '100px');
        }

    });

});

        $("#invisibility").toggle(function(){
        $('fieldset').css('visibility', 'hidden');
    }, function(){
        $('fieldset').css('visibility', 'visible');
    });

});

我正在使用 jquery cookie 插件,但是当我刷新页面时它恢复正常。我正在编写一个网站,我在其中使用字段集将一个框移动到某个位置,但是当我刷新我的页面时,框移回它的原始位置,而不是我在刷新之前设置的位置。

4

1 回答 1

0

好吧,如果你location像这样创建cookie

 var lastsettings = $.cookie('location');

...然后,下一步是为此类 cookie 分配一个值,例如

$.cookie('location', 'blue');

...但您将值设置为不存在的 cookie

$.cookie('position', 'blue');
于 2012-11-08T05:32:04.483 回答