jquery插件cookies的使用
jQuery #cookies #插件2012-07-10 10:03
先上下代码:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script> //插入js
<script type="text/javascript" src="jquery.cookies.2.2.0.min.js"></script>//插入插件。注意:这个插件一定要放在jquery文件的后面,否则不会生效
<script type="text/javascript">
$(document).ready(function(){
$(".tijiao").click(function(){ //触发button事件
$.cookies.set('name',$(".userName").value);
$.cookies.set('password',$(".password").value); //把表单中得到的value存入cookie
alert("已经存入cookie");
});
var userN=$.cookies.get( 'name' );
var userP=$.cookies.get( 'password' ); //从cookie中读取数据
if(userN!=""&&userN!=null&&userP!=""&&userP!=null)
{$(".userName").value=userN;
$(".password").value=userP; // 赋值
}
else{
alert("userName or password is not exist");};
})
</script>
</head>
<body>
<div>
<table>
<tr id="name">
<td><lable>用户名:</lable></td>
<td><input type="text" class="userName" value=""/></td>
</tr>
<tr>
<td><lable>密码:</lable></td>
<td><input type="password1" class="password" value=""/></td>
</tr>
<tr>
<td><input type="button" class="tijiao" value="登录"/></td>
</tr>
</table>
</div>
</body>
</html>要想设置cookie的其他属性就看这个:var newOptions = {
domain: '*.mydomain.com',//设置域
path: '/somedir',//设置路径
expiresAt: new Date( 2011, 1, 1 ),//设置cookie失效时间
hoursToLive:0.01//设置cookie存活时间
secure: true//是否保护
}jquery插件cookies的下载地址:http://code.google.com/p/cookies/downloads/list
相关的文档:
http://code.google.com/p/cookies/wiki/Documentation
相关文章
- jquery实现分页的例子 2012/07/03
- jquery实现的Tabs切换 2012/07/03
- jQuery实现号码抽奖 2012/06/29
- jQuery基础小记录 2012/06/28
- jQuery实现图片等比缩放以及预加载 2012/06/28
- jquery禁用右键/文本选择功能/复制按键 2012/06/19
- jquery中$().hover(func1, funct2)的用法 2012/06/14
- jQuery操作select相关方法 2012/06/13
- jQuery动态添加file的方法 2012/06/13
- jQuery常用函数及功能 2012/06/11