Cookie operations in js
A cookie is a short piece of information stored on a computer's hard disk as a key/value pair. The cookie storage capacity is approximately 4 kb, different browser manufacturers have slight differences in cookie size restrictions. The main essence of cookies is "recognition", which is used to do some things; cookies cannot get any other data from your hard disk, send computer viruses or get your email address. A cookie has a validity period. The default validity period of a cookie is from when the cookie is generated to when the browser is disabled. You can also set the cookie validity period to specify the expiration date; users can also disable or manually delete cookies.
// Add cookiefunction addCookie (objName, objValue, objHours) {var str = objName + "=" + escape (objValue ); // cookie content cookieName = cookieValue if (objHours> 0) {// The expiration time is not set for the last time. When the browser is disabled, the cookie automatically disappears var date = new Date (); var MS = objHours * 360*1000; date. setTime (date. getTime () + MS); str + = "; expires =" + date. toGMTString ();} document. cookie = str;} // The format of the cookie stored in js is: name1 = value1; name1 = value1; nam E1 = value1 when obtaining the cookie content, remember to add the trim method to remove spaces on both sides of the content. Otherwise, a problem may occur $ (function () {var email = ""; var arrStr = document. cookie. split (";"); // obtain all cookies for (var I = 0; I <arrStr. length; I ++) {// the cookie value var temp = arrStr [I]. split ("="); // each cookie is split if (temp [0]. trim () = "emailMsg") {// If the cookie name and input parameter are always email = temp [1] ;}/// indicates that the registration is successful, hide the registration box if (email! = "" & Email! = Null) {$ ("# welcome "). removeClass ("dn"); $ ("# login_msg "). addClass ("dn"); $ ("# welcome_msg "). text ("Welcome:" + email );}});