- 浏览: 204090 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
listen-raining:
你好。 我是这样写的: JButton b4=new ...
swing 初级学习(四)模式窗口取返回值 -
liu765023051:
灰常感谢~~
同一台机器上配置多个jboss应用服务器实例 -
Mr_Monotony:
为什么我按照这个写了不行啊?。。 只有自己才能看到信息。 而且 ...
Dwr推送技术学习 -
不过是过客:
太厉害了,IE上推送有问题,到处找,看到大哥这个试了一盘,没问 ...
Dwr推送技术学习
js读写COOKIE
- 博客分类:
- javaScript
js实现记住帐号或密码(js读写COOKIE)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test0417.aspx.cs" Inherits="test0417" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function onLoginLoaded()
{
if(isPostBack == "False")
{
GetLastUser();
}
}
function GetLastUser()
{
var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";
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 = 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 = "<%= IsPostBack %>";
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.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;
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("txtUserName").value;
var expdate = new Date();
SetCookie(usr, null, expdate);
}
</script>
</head>
<body onload="onLoginLoaded()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtUserName" runat="server" onblur="GetPwdAndChk()"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:CheckBox ID="chkRememberPwd" runat="server" Text="記住密碼" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="進入 " OnClientClick="SetPwdAndChk()"/>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test0417.aspx.cs" Inherits="test0417" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function onLoginLoaded()
{
if(isPostBack == "False")
{
GetLastUser();
}
}
function GetLastUser()
{
var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67";
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 = 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 = "<%= IsPostBack %>";
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.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;
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("txtUserName").value;
var expdate = new Date();
SetCookie(usr, null, expdate);
}
</script>
</head>
<body onload="onLoginLoaded()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtUserName" runat="server" onblur="GetPwdAndChk()"></asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:CheckBox ID="chkRememberPwd" runat="server" Text="記住密碼" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="進入 " OnClientClick="SetPwdAndChk()"/>
</div>
</form>
</body>
</html>
发表评论
-
JQuery UI - droppable
2012-02-21 16:24 1239·概述 配合draggable ... -
jquery ui drap
2012-02-21 16:02 1004[原文翻译] JQuery UI Draggable插件用来使 ... -
JS中获取request的值,非常好用的JS代码
2012-02-15 13:50 11002JS中获取request的值,非常好用的JS代码 项目中 ... -
js math
2010-08-10 11:48 2152.丢弃小数部分,保留整 ... -
ajax 再学习(三)简单示例
2010-07-13 11:31 809实现简单流程,需要2步: 1、ajaxTest.htm ... -
ajax 再学习(二)
2010-07-13 11:06 906XMLHttpRequest对象的三个属性: 1、on ... -
ajax 再学习(一)
2010-07-13 11:01 804//根据不同的浏览器创建相应的XMLHttpRequest对象 ... -
js
2010-07-12 17:42 824<!DOCTYPE HTML PUBLIC " ... -
js radio(一)
2010-04-08 20:04 1262取页面的值 <script> f ... -
js 控制 Windows Media Player
2010-02-19 19:27 6028Windows Media Player html: &l ... -
DWR 传递数组、MAP参数
2010-01-06 16:15 3201js部分: function aa(){ ... -
js 计算器(二)
2009-12-21 11:18 918简单实现基本运算 <%@ page langua ... -
js 计算器
2009-12-21 11:17 1273科学计算器 <%@ page language= ... -
window open
2009-12-10 15:25 821window.open("*.jsp",& ... -
IE功能汇集(三)
2009-12-10 14:13 807<body><SCRIPT LANGUA ... -
IE功能汇集(二)
2009-12-10 14:12 913鼠标自定义 <script language ... -
IE功能汇集(一)
2009-12-10 14:11 787其实这篇文章我在asp版 ... -
打开服务器上的文件
2009-12-01 14:25 925<script type="text/java ... -
jsewweweew
2009-11-25 15:22 655<% pageContext.setAttribute( ... -
js 文件夹选择框(三)
2009-11-20 16:40 1962本文来自:Web技术之家(www.waweb.cn ...
相关推荐
详细介绍js读写cookie的方法 function cookeid get()
js 实现 读写Cookie的函数! 值得下载看看!资源免费,大家分享!!
javascript 读写cookie对象 Cookie.write() //写 Cookie.read() //读 Cookie.remove() //删除
js COOKIE 记住帐号或密码 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]测试方法:加入先输入用户名jb51密码为 www.jb51.net,选择记住密码,然后关闭后,重新打开页面,在用户名里面输入jb51,则密码会自动...
今天小编就为大家分享一篇关于Javascript读写cookie的实例源码,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
下面小编就为大家带来一篇用js读写cookie的简单方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
介绍了C# javascript 读写Cookie的方法,有需要的朋友可以参考一下
前端js读写删cookie
使用js实现一个页面浮层效果,用js读写cookie来实现用户关闭广告的显示状态,下面有个不错的示例,感兴趣的朋友可以参考下
Flex 与javascript交互、C#读写Cookie代码
测试页面 博文链接:https://callan.iteye.com/blog/161777
javascript对cookie的日常操作
java-script读写Cookie例子
js操作Cookie包括:写cookies、读取cookies、删除cookies以及使用示例,感兴趣的朋友可以参考下哈
简单的小例子 ,JS 操作COOKIE都用到了 增,删, 读 把JS数据放到COOKIE里是为了防止页面刷新后JS数据失去等等之类。 进去看下页面代码就很容易了