复制代码 代码如下:
<!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="/UploadFiles/2021-04-02/jquery-1.10.2.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.cookie.js"><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>
<!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="/UploadFiles/2021-04-02/jquery-1.10.2.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.cookie.js"><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>
标签:
cookie插件,保存数据
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“jQuery的cookie插件实现保存用户登陆信息”评论...