2013-04-01 246 views
0
<!-- Modal --> 
<div id="appsmodal" class="modal hide fade" tabindex="-1" role="dialog" 
aria-labelledby="myModalLabel" aria-hidden="true"> 
<div class="modal-header"> 
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
<h3 id="myModalLabel">Modal header</h3> 
</div> 
<div class="modal-body"> 
<p>One fine body…</p> 
</div> 
<div class="modal-footer"> 
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
<button class="btn btn-primary">Save changes</button> 
</div> 
</div> 
<script type="text/javascript"> 
    $(document).ready(function() { 

     if($.cookie('msg') == 0) 
     { 
      $('#appsmodal').modal('show'); 
      $.cookie('msg', 1); 
     } 

    }); 
</script> 

我一直在为大约一个小时而烦恼,但无济于事。在使用我所有的资源之前,我不想问问题。Jquery Cookie代码不能正常工作

+0

这是一个.length的东西?如果(!$。cookie('msg')。length)还是类似的?如果cooke'msg'没有被设置,它不会等于0.它不会存在。 – orolo

+0

.length?是吧? jquery cookie.js和bootstrap modal – Binary101010

+0

我想知道如果你是否“如果($ .Cookie('味精')== 0)永远不会返回true,因为如果你还没有设置$ .cookie('味精'),它不会== 0它只是不会存在,但是,询问$ .cookie('msg')。length == 0是否可能会返回所需内容 – orolo

回答

1

从文档https://github.com/carhartl/jquery-cookie

Create session cookie: 

$.cookie('the_cookie', 'the_value'); 
Create expiring cookie, 7 days from then: 

$.cookie('the_cookie', 'the_value', { expires: 7 }); 
Create expiring cookie, valid across entire site: 

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); 
Read cookie: 

$.cookie('the_cookie'); // => "the_value" 
$.cookie('not_existing'); // => undefined 
Read all available cookies: 

$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" } 
Delete cookie: 

有浏览器的控制台打开并检查是否有任何错误陈述(是否包括cookie的库,例如)。另外,请在浏览器中使用检查器以确保cookie实际上已设置:http://getfirebug.com/cookies

+0

谢谢orolo。非常感谢 – Binary101010

1

最后!

我想通了。 Joomla问题

+0

酷!感谢更新。 – orolo