JS¶ÁÈ¡cookie£¨¼ÇסÕ˺ÅÃÜÂ룩
ºÜ¶àµÇ¼¹¦ÄÜÉ϶¼Óиö¡°¼ÇסÃÜÂ롱µÄ¹¦ÄÜ£¬ÆäʵÎ޷ǾÍÊǶÔcookieµÄ¶ÁÈ¡¡£
ÏÂÃæչʾÕâ¸ö¹¦ÄܵĴúÂ룬Ô×÷ÕßÒÑÎÞ·¨¿¼¾¿¡£¡£¡£¡£
²âÊÔ·½·¨£ºÖ±½ÓÊäÈëÕ˺ÅÃÜÂ룬Ìá½»ºó£¬Ë¢ÐÂÒ³Ã棬ÔÙÊäÈëͬÑùµÄÕ˺ţ¬¾Í¿ÉÒÔÏÔʾ
<!DOCTYPE HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js COOKIE ¼ÇסÕʺŻòÃÜÂë</title> <script type="text/javascript"> window.onload=function onLoginLoaded() { if (isPostBack == "False") { GetLastUser(); } } function GetLastUser() { var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";//GUID±êʶ·û var usr = GetCookie(id); if (usr != null) { document.getElementById('txtUserName').value = usr; } else { document.getElementById('txtUserName').value = "001"; } GetPwdAndChk(); } //µã»÷µÇ¼ʱ´¥·¢¿Í»§¶Ëʼþ function SetPwdAndChk() { //È¡Óû§Ãû var usr = document.getElementById('txtUserName').value; alert(usr); //½«×îºóÒ»¸öÓû§ÐÅϢдÈëµ½Cookie SetLastUser(usr); //Èç¹û¼ÇסÃÜÂëÑ¡ÏѡÖÐ if (document.getElementById('chkRememberPwd').checked == true) { //È¡ÃÜÂëÖµ var pwd = document.getElementById('txtPassword').value; alert(pwd); var expdate = new Date(); expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); //½«Óû§ÃûºÍÃÜÂëдÈëµ½Cookie SetCookie(usr, pwd, expdate); } else { //Èç¹ûûÓÐÑ¡ÖмÇסÃÜÂë,ÔòÁ¢¼´¹ýÆÚ ResetCookie(); } } function SetLastUser(usr) { var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67"; var expdate = new Date(); //µ±Ç°Ê±¼ä¼ÓÉÏÁ½ÖܵÄʱ¼ä expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); SetCookie(id, usr, expdate); } //Óû§Ãûʧȥ½¹µãʱµ÷Óø÷½·¨ function GetPwdAndChk() { var usr = document.getElementById('txtUserName').value; var pwd = GetCookie(usr); if (pwd != null) { document.getElementById('chkRememberPwd').checked = true; document.getElementById('txtPassword').value = pwd; } else { document.getElementById('chkRememberPwd').checked = false; document.getElementById('txtPassword').value = ""; } } //È¡CookieµÄÖµ function GetCookie(name) { var arg = name + "="; var alen = arg.length; var clen = [removed].length; var i = 0; while (i < clen) { var j = i + alen; //alert(j); if ([removed].substring(i, j) == arg) return getCookieVal(j); i = [removed].indexOf(" ", i) + 1; if (i == 0) break; } return null; } var isPostBack = "<%= IsPostBack %>"; function getCookieVal(offset) { var endstr = [removed].indexOf(";", offset); if (endstr == -1) endstr = [removed].length; return unescape([removed].substring(offset, endstr)); } //дÈëµ½Cookie function SetCookie(name, value, expires) { var argv = SetCookie.arguments; //±¾ÀýÖÐlength = 3 var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; [removed] = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } function ResetCookie() { var usr = document.getElementById('txtUserName').value; var expdate = new Date(); SetCookie(usr, null, expdate); } </script> </head> <body> <form id="form1"> <div> Óû§Ãû: <input type="text" ID="txtUserName" onblur="GetPwdAndChk()"> <input type="password" ID="txtPassword"> ÃÜÂ룺 <input type="checkbox" ID="chkRememberPwd" /> ¼ÇסÃÜÂë <input type="button" OnClick="SetPwdAndChk()" value="½øÈë"/> </div> </form> </body> </html>
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ