jQuery를 이용한 ID/PW cookie 저장 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
var cookieIdKeyStr = "USER_ID";
var cookiePwKeyStr = "USER_PW";
$(document).ready(function(){
<%-- 쿠키값을 읽어와 ID/PW 체크 --%>
if( $.cookie(cookieIdKeyStr)!="" && $.cookie(cookieIdKeyStr)!=null ) {
$("#cb_idSave").attr("checked", "checked");
$("#textMemberId").val($.cookie(cookieIdKeyStr));
}
if( $.cookie(cookiePwKeyStr)!="" && $.cookie(cookiePwKeyStr)!=null ) {
$("#cb_pwSave").attr("checked", "checked");
$("#textMemberPw").val($.cookie(cookiePwKeyStr));
}
});
function check() {
checkSaveIdPw();
}
<%-- ID/PW 저장 체크 --%>
function checkSaveIdPw() {
var checkStatus = $("#cb_idSave").is(":checked");
if( checkStatus ) {
$.cookie(cookieIdKeyStr, $("#mnMemberCode").val(), { expires: 30 });
} else {
$.cookie(cookieIdKeyStr, null);
}
checkStatus = $("#cb_pwSave").is(":checked");
if( checkStatus ) {
$.cookie(cookiePwKeyStr, $("#mnMemberPwd").val(), { expires: 30 });
} else {
$.cookie(cookiePwKeyStr, null);
}
}
|
jQuery cookie 사용법
$.cookie('the_cookie'); //cookie취득
$.cookie('the_cookie', 'the_value'); //cookie를 셋팅
$.cookie('the_cookie', 'the_value', { expires: 7 }); //쿠키의 유효기간을 7일간으로 지정
$.cookie('the_cookie', '', { expires: -1 }); //cookie 삭제
$.cookie('the_cookie', null); //cookie 삭제
https://github.com/carhartl/jquery-cookie // jQuery 쿠키 js 다운로드 및 참조
참고 : http://blog.naver.com/PostView.nhn?blogId=lazyker&logNo=110132802552