Jquery Cookie代码无效

时间:2013-04-01 19:28:12

标签: jquery twitter-bootstrap jquery-cookie

<!-- 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>

我已经被大约一个小时感到困惑现在无济于事。在我用完所有资源之前,我不想提问。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

最后!

我明白了。 Joomla问题