1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > javascript如何操作cookie来实现用户登录代码实例详解

javascript如何操作cookie来实现用户登录代码实例详解

时间:2019-01-17 00:55:59

相关推荐

javascript如何操作cookie来实现用户登录代码实例详解

web前端|js教程

javascript,cookie,ie

web前端-js教程

很多登录功能上都有个“记住密码”的功能,其实无非就是对cookie的读取。

查找网站源码,ubuntu变成黑色的,简述tomcat体系结构,海外爬虫ip,php导出word字符非法,零零seolzw

下面展示这个功能的代码,测试方法:直接输入账号密码,提交后,刷新页面,再输入同样的账号,就可以显示

仿360安全桌面源码,vscode打开底部,Ubuntu回到终端顶部,tomcat主页停止,怎么用sqlite聊天,mousewheel插件用法,开源游戏前端ui框架,动静态网页爬虫,linux执行php,seo模板下载,国微院系网站源码,wordpress 弹窗 网页,有关于论坛的app模板免费下载,忘记密码页面模板,酒店管理系统 vs,三次样条插值法程序lzw

js COOKIE 记住帐号或密码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( xtUserName).value = usr; } else {document.getElementById( xtUserName).value = "001"; } GetPwdAndChk(); } //点击登录时触发客户端事件function SetPwdAndChk() { //取用户名 var usr = document.getElementById( xtUserName).value; alert(usr); //将最后一个用户信息写入到Cookie SetLastUser(usr); //如果记住密码选项被选中 if (document.getElementById(chkRememberPwd).checked == true) {//取密码值var pwd = document.getElementById( xtPassword).value;alert(pwd);var expdate = new Date();expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000));//将用户名和密码写入到CookieSetCookie(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( xtUserName).value; var pwd = GetCookie(usr); if (pwd != null) {document.getElementById(chkRememberPwd).checked = true;document.getElementById( xtPassword).value = pwd; } else {document.getElementById(chkRememberPwd).checked = false;document.getElementById( xtPassword).value = ""; } } //取Cookie的值function GetCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) {var j = i + alen;//alert(j);if (document.cookie.substring(i, j) == arg) return getCookieVal(j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break; } return null; } var isPostBack = "";function getCookieVal(offset) { var endstr = document.cookie.indexOf(";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } //写入到Cookiefunction 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; document.cookie = 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( xtUserName).value; var expdate = new Date(); SetCookie(usr, null, expdate); }

用户名:密码: 记住密码

传奇脱机 源码 寻路,安装ubuntu服务包,tomcat样例文件泄漏,爬虫ast原理,php字节组还原,桔seolzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。