您的位置:首页 > 产品设计 > UI/UE

jquey实现对cookie的操作

2016-02-01 11:17 344 查看
步骤:

《一》:引入jquery.cookie.js插件(其实就是jquey对cookie操作进行了封装)和jquery.js文件

《二》:代码示例:

    

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jquey之cookie用法</title>
<script src="../js/jquery-1.8.0.js"></script>
<script src="../js/jquery.cookie.js"></script>
<script>
$(function(){
var expiresDate= new Date();
expiresDate.setTime(expiresDate.getTime() + (3000));  //设置cookie有效时间为3秒

//    $.cookie("username","许文祥",{expires:1});  //设置cookie有效时间为1天
$.cookie("username","许文祥",{expires:expiresDate});  //设置cookie

if($.cookie("username") != null)  //判断cookie值是否存在
{
alert("username的cookie值为:"+$.cookie("username"));
}
else
{
alert("没有username的cookie值");
}

});
</script>
</head>
<body>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: