js怎么写Cookie

html:

1 <div id="dcookie">
2         <input type="text"  id="txtCookie"/>
3         <input type="button" value="测试cookie" id="dtextc" onclick="TextCookie()" />
4         <input type="button" value="删除cookie"  onclick="DelCookie()"/>
5 </div>

 

js:

 1 $(function () {
 2     var c = $.cookie("mycookie");
 3     if (c == null) {
 4         alert("没有cookie");
 5     }
 6     else {
 7         alert(c);
 8     }
 9 }
10 //设置Cookie
11 function TextCookie() {
12     var user = $.trim($("#txtCookie").val());
13     $.cookie("mycookie", user, {
14         expires: 1,
15         path: "/"
16     });
17 }
18 //删除Cookie
19 function DelCookie() {
20     $.cookie("mycookie", null, {
21         path: "/"
22     });
23 }

 

posted @ 2017-02-23 22:54  ~Jungle  Views(279)  Comments(0Edit  收藏  举报