码迷,mamicode.com
首页 > Web开发 > 详细

记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名!

时间:2014-12-31 17:40:24      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

// 记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名!


var
username = document.getElementById("username"); var password = document.getElementById("password"); var date=new Date(); var expiresDays=1000; //过期时间。 date.setTime(date.getTime()+expiresDays*24*3600*1000); var str_in; var str_out = ""; var num_in; var num_out = ""; //加密 function str_to_num(val) { num_out = ""; //if(form.input.value == "") alert(e); //else { str_in = escape(val); for(i = 0; i < str_in.length; i++) { num_out += str_in.charCodeAt(i) - 23; } //form.output.value = num_out; //form.input.value = ""; return num_out; } //解密 function num_to_str(val) { str_out = ""; num_out = val; for(i = 0; i < num_out.length; i += 2) { num_in = parseInt(num_out.substr(i,[2])) + 23; num_in = unescape(‘%‘ + num_in.toString(16)); str_out += num_in; } var str_out_jm = unescape(str_out); return str_out_jm ; } $(function(){ $(".data_sub.sub_click").click(function(){ if(document.getElementById("checkBox").checked){ document.cookie = "a="+ str_to_num(username.value)+"; expires=" + date.toGMTString(); ; document.cookie = "b="+ str_to_num(password.value)+"; expires=" + date.toGMTString(); }else{ return; } }); var user = getCookie("a"); var pass = getCookie("b"); if(username.value == "") { username.value = num_to_str(user); } if(password.value == ""){ password.value = num_to_str(pass); } }); }); function getCookie(name){ var strCookie=document.cookie; var arrCookie=strCookie.split("; "); for(var i=0;i<arrCookie.length;i++){ var arr=arrCookie[i].split("="); if(arr[0]==name)return arr[1]; } return ""; }

 

记住密码功能 JS结合JQuery 操作 Cookie 实现记住密码和用户名!

标签:

原文地址:http://www.cnblogs.com/loverows/p/4195894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!