Can't read jQuery cookies but can set them, "Uncaught TypeError: $.cookie is not a function"

Can't read jQuery cookies but can set them, "Uncaught TypeError: $.cookie is not a function"

发生了一件奇怪的事情。我正在使用 jQuery 和一个名为 JS Cookie 的 Plugin/lib。

我的 HTML 脑子里有这个:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="scripts/js-cookie-master/src/js.cookie.js"></script>
<script src="scripts/cookiesetter.js"></script>

JS:

$(document).ready(function(){

$( ".close" ).click(function() {
    Cookies.set('increase', '1', { expires: 7 });
    $( "#popup, #overlay" ).hide();
});

if ( $.cookie("increase")); {
        return;
    }

    alert('test');
});

cookie 的输出:

increase - 1

好的,所以没坏。

但是当我尝试使用以下代码读取 cookie 时:

    if ( $.cookie("increase")); {
        return;
    }

    alert('test');

我得到的错误是:

Uncaught TypeError: $.cookie is not a function

怎么办?

我搜索了 Google、Whosebug 等。按照所有步骤检查了正确的加载顺序。

提前致谢!

$.cookie() 不是 jQuery nor of JS Cookie 的函数。

改为使用 Cookies.get('name') 检索 cookie。


正如所说:

I'm surprised it works since your semi-colon is out of place on your if statement

if ( $.cookie("increase")); {
                          ^----- remove