<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.8.2.min.js"></script>
<script src="Scripts/jquery.cookie.js"></script>
<script type="text/javascript">
$(function () {
$("#btnLogin").click(function () {
var strName = $("#txtName").val();
var strPwd = $("#txtPwd").val();
if (strName == "sa" && strPwd == "123") {
$.cookie("userName", strName, { expires: 1 });//没有设置失效时间,所以是缓存cookie,有设置失效时间则是硬盘cookie,expires单位是天
alert("登陆成功");
window.location.href = "11Index.html"; }
});
});
</script>
</head>
<body>
用户名:<input type="text" id="txtName" /><br />
密码:<input type="text" id="txtPwd" /><br />
<input type="button" id="btnLogin" value="登录" />
</body>
</html>

  登陆后的页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.8.2.min.js"></script>
<script src="Scripts/jquery.cookie.js"></script>
<script type="text/javascript">
$(function () {
var strName = $.cookie("userName");
if (strName && strName != "")//判断既不为null也不为undefined 和不为空字符串
{
$('#userName').text();
} else {
alert("请先登录");
window.location = '10Cookie.html';
} });
//退出方法
function exit() {
$.cookie("userName", "", { expires: -1 });//设置过期
alert("退出成功");
}
</script>
</head>
<body>
首页,欢迎<span id="userName"></span>
<a href="javascript:exit()">退出登录</a>
</body>
</html>

  

10Cookie的更多相关文章

随机推荐

  1. 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe

    题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. android——fragment长时间home或者锁屏java.lang.IllegalArgumentException:No view found for id for....

    在项目中遇到了这个问题.头痛了很久,总是无法重现,也不能很好的解决.总是在息屏后一段时间,就会报java.lang.IllegalArgumentException:No view found for ...

  3. 如何在美国公司写project plan 邮件--以hadoop安装和Mahout数据分析为例子

    Hi, XXX (boss name) Project Title:  Hadoop installation and Data analysis based on Mahout Deliverabl ...

  4. Repeater动态添加行

    <table class="table table-striped table-bordered table-hover">            <asp:Re ...

  5. struts1:Struts的中央控制器

    在Struts框架中,有多个组件分担控制器的工作,它们分别是ActionServlet类,RequestProcessor类和Action类等,其中ActionServlet是Struts框架中的核心 ...

  6. HDU 2157 - How many ways??

    给图,图中任意可达的两点间步数为1 问从图中A点走到B点步数为k的有几条路 祭出离散数学图论那章中的 邻接矩阵A. 设S=Ak 则 S[a][b] 为 a到b,步数为k的不同路的条数 剩下的就是矩阵快 ...

  7. 3D模型制作

    agisoft: http://www.agisoft.com/downloads/installer/ http://pan.baidu.com/s/1dDwA3tf http://pan.baid ...

  8. Router和History (路由控制)-backbone

    Router和History (路由控制) Backbone.Router担任了一部分Controller(控制器)的工作,它一般运行在单页应用中,能将特定的URL或锚点规则绑定到一个指定的方法(后文 ...

  9. pat_1

    2-0 2-1 #include <stdio.h> int main() { int inch,foot,cm; scanf("%d",&cm); foot= ...

  10. 使用bootstrap时,选项框出现的意外效果,怎么办?

    <label for="" style="float:right;margin-right:10%;">     <input type=&q ...