코드 사본은 다음과 같습니다.
/*
쿠키 도구
사용 방법 :
// 값을 저장합니다
var value = "7 일";
공구.
// 값을 얻습니다
var v = thooks.cookie ( "day");
*/
툴.cookie = 함수 (이름, 값, 옵션) {
if (typeof value! = 'undefined') {// 이름과 값 주어진 쿠키를 설정하십시오.
옵션 = 옵션 || {};
if (value === null) {
값 = '';
옵션 .expires = -1;
}
var 만료 = '';
if (옵션 .expires
&& (typeof options.expires == '번호'|| 옵션.expires.togmtstring)) {
var 날짜;
if (typeof options.expires == 'number') {
날짜 = 새 날짜 ();
날짜 .settime (date.gettime ()
+ (옵션 .expires * 24 * 60 * 60 * 1000);
} 또 다른 {
날짜 = 옵션 .expires;
}
만료 = '; 만료 =' + date.togmtstring ();
// 기인하다,
// Max-Age는 아닙니다
// IE에 의해 지원됩니다
}
var path = 옵션. ';
var domain = 옵션. 도메인 = ' + 옵션 :' ';
var secure = secure ';
document.cookie = [name, '=', encodeUricomponent (value), 만료,
경로, 도메인, 보안] .join ( '');
} else {// 주어진 이름 만 쿠키를 얻으십시오
var cookievalue = null;
if (document.cookie && document.cookie! = '') {
var 쿠키 = document.cookie.split ( ';');
for (var i = 0; i <cookies.length; i ++) {
var 쿠키 = jQuery.trim (쿠키 [i]);
//이 쿠키 스트링은 우리가 원하는 이름으로 시작합니까?
if (cookie.substring (0, name.length + 1) == (이름 + '=')) {
Cookievalue = DecodeUricomponent (쿠키
.substring (name.length + 1));
부서지다;
}
}
}
Cookievalue를 반환하십시오.
}
};