<!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>
<title></title>
<script src="../js/Jquery-1.4.2.js" type="text/javascript"></script>
<script src="../js/jquery-cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
if ($.cookie("UserName")) {//如果有值得话,则在文本中显示
$("#UserName").val($.cookie("UserName"))
}
$("#sbtUser").submit(function () {//表单提交事件
if ($("#chkSave").attr("checked")) {//如果选中了保存用户名
//设置cookie值
$.cookie("UserName", $("#UserName").val(), { path: "/", expires: 7 })
}
else {
//销毁cookie
$.cookie("UserName", null, {path:"/"})
}
return false;//表单不提交
})
});
</script>
</head>
<body>
<form action="#" method="get" id="frmUserInfo">
<div class="divFrame">
<div class="divTitle">用户登录:
</div>
<div class="divContent">
<div>用户名:<br/>
<input type="text" name="UserName" class="txt" id="UserName" />
</div>
<div>密码:<br/>
<input type="password" name="UserPass" class="txt" id="UserPass" />
</div>
<div>
<input type="checkbox"
id="chkSave"/>是否保存用户名</div>
</div>
<div class="divBtn">
<input id="sbtUser" type="submit" value="提交" class="btn" />
</div>
<div id="divData"></div>
</div>
</form>
</body>
</html>
Cookie插件小案例,布布扣,bubuko.com
Cookie插件小案例
原文:http://blog.csdn.net/qizhichao110/article/details/25068535