jQuery的cookie插件实现保存用户登陆信息

2019-12-21,,,

复制代码 代码如下:
<!DOCTYPE html>
<html>
<head>
<title>cookies.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<style type="text/css">
.txt{
width: 150px;
height:20px;
border: 1px blue solid;
border-radius:0.5em;
margin-bottom: 5px;
padding-left: 5px;
}

</style>
<script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/jquery.cookie.js"></script>
<script type="text/javascript">
$(function(){


if($.cookie("name")){
//取值如果存在则赋值
$("#username").val($.cookie("name"));

}


$("#mycookie").submit(function(){

//如果选中了保存用户名选项
if($("#chkSave").is(":checked")){

//设置Cookie值
$.cookie("name",$("#username").val(),{
expires:7,//设置保存期限
path:"/"//设置保存的路径

});

}else{

//销毁对象
$.cookie("name",null,{
path:"/"

});
}

return false;
});

});


</script>
</head>
<body>
<form action="#" method="get" id="mycookie">

<div>
用户名:<br>
<input id="username" name="username" type="text" class="txt">
</div>
<div>
密码:<br>
<input id="password" name="password" type="password" class="txt">
</div>
<div>
<input id="chkSave" type="checkbox">是否保存用户名
</div>
<div>
<input id="cookBtn" class="btn" type="submit" value="提交">
</div>

</form>
</body>
</html>

您可能感兴趣的文章:

  • 通过Jquery.cookie.js实现展示浏览网页的历史记录超管用
  • jquery使用Cookie和JSON记录用户最近浏览历史
  • jquery.cookie() 方法的使用(读取、写入、删除)
  • jquery.cookie用法详细解析
  • 使用jQuery操作Cookies的实现代码
  • jquery.cookie.js 操作cookie实现记住密码功能的实现代码
  • jQuery操作cookie方法实例教程
  • 基于jquery的cookie的用法
  • jQuery控制cookie过期时间的方法
  • 怎样使用php与jquery设置和读取cookies
  • jquery cookie插件代码类
  • jquery插件如何使用 jQuery操作Cookie插件使用介绍
  • jQuery.cookie.js实现记录最近浏览过的商品功能示例

《jQuery的cookie插件实现保存用户登陆信息.doc》

下载本文的Word格式文档,以方便收藏与打印。