关于jquery 的cookie插件 (Jquery基础课程9-5习题)

<!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>cookie插件</title>
       <link href="style.css" rel="stylesheet" type="text/css" />
       <script type="text/javascript" src="http://www.imooc.com/data/jquery-1.8.2.min.js"></script>
       <script src="http://www.imooc.com/data/jquery.cookie.js" type="text/javascript"></script>
   </head>
   
   <body>
       <div id="divtest">
           <div class="title">
               <span class="fl">cookie插件</span>
               <span class="fr">
                   <input id="btnSet" type="button" value="设置" />
               </span>
           </div>
           <div class="content">
               <span class="fl">邮箱:</span><br />
               <input id="email" name="email" type="text" /><br />
               <input id="chksave" type="checkbox" />是否保存邮箱
           </div>
       </div>
       
       <script type="text/javascript">
           $(function () {
               if ($.cookie("email")) {  
                   $("#email").val($.cookie("email"));
               }
               if($.cookie("che")){
                   $("#chksave").attr("checked",true);
               }
               $("#btnSet").bind("click", function () {
                   if ($("#chksave").is(":checked")) {
                       $.cookie("email",$("#email").val(), {
                           path: "/", expires:  7
                       }),
                       $.cookie("che",true, {
                           path: "/", expires:  7
                       })  
                   }                            
                   else {  
                       $.cookie("email",null, {
                           path: "/"      
                       }),
                       $.cookie("che",null, {
                           path: "/"
                       })
                   }
               });
           });
       </script>
   </body>
</html>

qq_甘蔗_0
浏览 1504回答 2
2回答

李晓健

cookie是需要种到域名或ip下面的。所以你本地需要有一个web服务。访问时不要用localhost来访问,用ip或127.0.0.1 

喵呜_0001

先回答楼主的问题,cookie和服务器并无关系。cookie的机制受很多因素影响,其中有浏览器安全设置,建议你先检查一下浏览器支不支持cookie存储,我记得mac就不行,课程里的试验,我在自己电脑上试过,是没有问题的。另外,楼主你引用的不是cookie插件啊喂【汗】
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery