jQuery cookie值是%5Bobject%20Object%5D

Ali*_*can 3 javascript cookies jquery

我有一个简单的html页面和一个js脚本:HTML页面:

<body>
<input type="text" id = "content">
<button type="button" id="btn"> Save </button>
</body>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$(document).ready( function(){
    var cook = $.cookie('theName',  { path: '/'});
     if ( cook )
        alert(cook); 
    $('#btn').click(function(){
        var theName = $('#content').val();
        alert(v.val());
        $.cookie('theName', theName, { path: '/', expires: 7 });
        alert("Cookie done");
    });
});
Run Code Online (Sandbox Code Playgroud)

图书馆:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"> </script>
<script type="text/javascript" src = "https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js"> </script>
Run Code Online (Sandbox Code Playgroud)

它应该保存我的名字,当我点击刷新以显示我的名字.唯一的问题是当我尝试读取cookie时,而不是名称显示%5Bobject%20Object%5D.

谢谢.

Sud*_*oti 5

做:

$(document).ready( function(){
    var cook = $.cookie('theName'); //get from cookie if exists
     if ( cook )
        alert(cook); 
    $('#but').click(function(){
        var theName = $('#content').val();
        alert(theName);
        $.cookie('theName', theName, { expires: 7, path: '/' }); //set the cookie
        alert("Cookie done");
    });
});
Run Code Online (Sandbox Code Playgroud)

更新:

尝试添加:

$.cookie.raw = true;
Run Code Online (Sandbox Code Playgroud)