Core code:
Copy Code code as follows:
var cookie={
Setcookie:function (name, value, Iday) {
var odate = new Date ();
Odate.setdate (Odate.getdate () +iday);
Document.cookie = name+ ' = ' +value+ '; expires= ' +odate;
},
Getcookie:function (name) {
var arr = Document.cookie.split ('; ');
for (var i = arr.length-1 i >= 0; i--) {
var arr2 = arr[i].split (' = ');
if (arr2[0]===name) {
return arr2[1];
}
}
Return ";
},
Removecookie:function (name) {
Cookie.setcookie (name,1,-1);
}
};
Test:
<textarea id="runcode59136"><ptml> <pead> <title></title> </pead> <script> var cookie={setcookie:fun Ction (name, value, Iday) {var odate = new Date (); Odate.setdate (Odate.getdate () +iday); Document.cookie = name+ ' = ' +value+ '; expires= ' +odate; }, Getcookie:function (name) {var arr = document.cookie.split ('; '); for (var i = arr.length-1 i >= 0; i--) {var arr2 = arr[i].split (' = '); if (arr2[0]===name) {return arr2[1]; } return '; }, Removecookie:function (name) {Cookie.setcookie (name,1,-1); } }; Cookie.setcookie (' username ', ' Iceshu ', 33); Setcookie (' pwd ', ' FF ', 365); Cookie.removecookie (' username '); Alert (document.cookie) alert (Cookie.getcookie (' pwd ')); </script> <body> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]