2012-01-29 4 views
0

jQuery로 쿠키를 설정하는 방법 (jQuery 쿠키 플러그인 사용)에 대한 자습서를 찾았습니다. 모든 쿠키는 나보다 경험이 많은 사람들을 대상으로합니다. 내가 쿠키를 통해 #whatever의 배경 노란색 유지할 수있는 방법jQuery로 쿠키 설정

<button>Example</button> 
<div id="whatever" style="background:red;">Test</div> 

<script> 
$('button').click(function() { 
    $('#whatever').css("background","yellow"); 
}); 
</script> 

:

는 여기에 몇 가지 예제 코드인가?

답변

3

글쎄, 그건 쉬워요는 다음과 같습니다

//on document ready, checks if the cookie is set, and if so, sets the background with it's value 
$(function(){ 
    if($.cookie("background") != null){ 
    $('#whatever').css("background", $.cookie("background")); 
    } 
}); 
//here you set the cookie, with the value you want 
$('button').click(function() { 
    $('#whatever').css("background","yellow"); 
    $.cookie("background", "yellow"); 
}); 
+0

딱! 고맙습니다. – UserIsCorrupt

+1

:) 완벽하면 대답을 받아 들일 수 있습니까? –