JQuery Cookie插件不起作用 - 没有定义jQuery

ger*_*nde 1 css cookies wordpress jquery

我意识到有很多这样的问题:忍受我.我和JQuery的关系不如HTML/CSS,我第一次使用cookies.我有这个网站有一个绿色横幅,当用户点击'X'时应该消失.

这是破坏的JQuery让我疯狂:

$(document).ready(function(){ 
    if (!$.cookie('thecookie') || $.cookie('thecookie')==null || $.cookie('thecookie')=="") { 
        $("#headershadow").hide();
        $("#bigx").click(function(){
            $("#greenbanner").hide(1000);
            $("#headershadow").show();
            $.cookie('thecookie', 'true', { expires: 1, path: '/' });
        });
    } else {
        $("#headershadow").show();
        $("#greenbanner").hide();
    }
});
Run Code Online (Sandbox Code Playgroud)

从本质上讲,我想知道为什么这会破裂.我需要在#greenbanner你第一次加载网站时显示,然后如果你点击bigx#greenbanner就会消失一天.我正在为JQuery cookie使用这个漂亮的插件.

任何帮助让这个停止破坏和工作将是太棒了.我一直在忙着这么久,我现在很恼火.

Ani*_*nil 5

在您的源代码中,您将在cookie插件(依赖于jQuery)之后包含jQuery .

<script src="jquery.cookie.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

切换这两个的顺序,它应该有助于解决您的问题..

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script src="jquery.cookie.js"></script>
Run Code Online (Sandbox Code Playgroud)

另外..你似乎有一堆或错误,Console首先解决这些问题,一切都应该按预期工作.