欢迎来到代码驿站!

jquery

当前位置:首页 > 网页前端 > jquery

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

时间:2021-04-11 08:52:58|栏目:jquery|点击:
复制代码 代码如下:

<!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插件FusionWidgets实现的Bulb图效果示例【附demo源码下载】

栏    目:jquery

下一篇:浅谈jQuery构造函数分析

本文标题:jQuery的cookie插件实现保存用户登陆信息

本文地址:http://www.codeinn.net/misctech/98727.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有