导航:首页 > 源码编译 > jsescape源码

jsescape源码

发布时间:2023-12-07 02:26:34

Ⅰ 100分 求js写的自动登陆帐号密码保存功能~源码

/**
* 操作Cookie 添加
* @param name
* @param value
* @return
*/
function SetCookie(name,value,days)//两个参数,一个是cookie的名子,一个是值
{
var Days = 30;
if(typeof(days)=="undefined"||isNaN(days))
Days=parseInt(days.toString());
//此 cookie 将被保存 30 天 -1为浏览器关闭
if(Days!=-1){
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}else{
document.cookie = name + "="+ escape (value) + ";expires=-1";
}
}

/**
* 操作Cookie 提取 后台必须是escape编码
* @param name
* @return
*/
function getCookie(name)//取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
/**
* 操作Cookie 删除
* @param name
* @return
*/
function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - (86400 * 1000 * 1));
var cval=getCookie(name);
if(cval!=null)
document.cookie = name + "="+ escape (cval) + ";expires="+exp.toGMTString();
}

/**
* 根据ID获取对象
* @param objName
* @return
*/
function GetObj(objName){
if(typeof(objName)=="undefined")
return null;
if(document.getElementById)
return eval('document.getElementById("'+objName+'")');
else
return eval('document.all.'+objName);

}
/**
* 给String 添加trim方法
*/
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
/**
* 给String添加isNullOrempty的方法
*/
String.prototype.isnullorempty=function(){
if(this==null||typeof(this)=="undefined"||this.trim()=="")
return true;
return false;

}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>
<script type="text/javascript" src="jsTool.js"></script>
<script type="text/javascript">
var cookieName_username="LOGIN_USER_NAME_TEST";
var cookieName_password="LOGIN_PASSWORD_TEST";
var cookieName_autologin="LOGIN_AUTO_TEST";

//得到Cookie信息
function getUserInfoByCookie(){
var uname=getCookie(cookieName_username);
if(uname!=null&&!uname.toString().isnullorempty()){
GetObj('ttuserName').value=uname;
GetObj('ck_saveuser').checked=true;
}

var upass=getCookie(cookieName_password)
if(upass!=null&&!upass.toString().isnullorempty()){
GetObj('ttpassword').value=upass;
GetObj('ck_savepass').checked=true;
}

var autologin=getCookie(cookieName_autologin)
if(autologin!=null&&!autologin.toString().isnullorempty())
if(autologin.toString().trim()=="true"){
GetObj('ck_autologin').checked=true;
login();//登录
}
}
/**
*登录(保存信息)
*/
function login(){
var tusername=GetObj('ttuserName');
if(tusername.value.trim().isnullorempty()){
alert('您尚未输入用户名!请输入!');
tpassword.focus();
return;
}
var tpassword=GetObj('ttpassword');
if(tpassword.value.trim().isnullorempty()){
alert('您尚未输入密码!请输入!');
tpassword.focus();
return;
}
delCookie(cookieName_username);//删除用户名Cookie
var tsaveuser=GetObj('ck_saveuser');
if(tsaveuser.checked)
SetCookie(cookieName_username,tusername.value.trim(),7);//保存到Cookie中 保存7天
delCookie(cookieName_password);//删除密码
var tsavepass=GetObj('ck_savepass');
if(tsavepass.checked)
SetCookie(cookieName_password,tpassword.value.trim(),7);
var autologin=GetObj('ck_autologin');
SetCookie(cookieName_autologin,autologin.checked,7);
alert('登录成功!');

}
</script>
</head>
<body onload="getUserInfoByCookie()">
用户名:<input type="text" value="" name="ttuserName" id="ttuserName" maxlength="16"/>
密码:<input type="password" value="" name="ttpassword" id="ttpassword" maxlength="16"/>
<input type="checkbox" name="ck_saveuser" id="ck_saveuser"/>保存用户名
<input type="checkbox" name="ck_savepass" id="ck_savepass"/>保存密码
<input type="checkbox" name="ck_autologin" id="ck_autologin"/>自动登录
<input type="button" value="登录(保存)" onclick="login()"/>
</body>
</html>
能不能审批呀

阅读全文

与jsescape源码相关的资料

热点内容
程序员会6点下班吗 浏览:791
linuxdate时区 浏览:319
小说服务器怎么选 浏览:520
python自动化测试框架哪个最好 浏览:305
反编译后为什么不能回编 浏览:48
java反射获得属性值 浏览:31
程序员和甲方的矛盾 浏览:126
在地狱做程序员 浏览:763
银行app能做什么 浏览:230
追书缓存的小说在哪个文件夹 浏览:555
山科女生程序员 浏览:746
mybatis3源码分析 浏览:461
华为交换机常用配置命令 浏览:378
程序员怎么去银行上班 浏览:591
广州程序员薪资 浏览:890
win7命令提示符输入 浏览:594
关于程序员的故事 浏览:484
吃鸡服务器是什么样的 浏览:26
为什么pspice没有单片机 浏览:12
高数第六版下册答案pdf 浏览:908