11

設定されている場合は a の値を取得し、その値で aをcookie更新しようとします。それ以外の場合は、80 ~ 100 の間の乱数を生成し、それを として設定し、次に を更新します。divcookiecookiediv

エラーが発生します:

Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie' 

ここに私のコードがあります:

$(document).ready(function(){

    var thecounter = '';

    if ($.cookie('thecounter') == null)
    {
        thecounter = $.randomBetween(80, 100);
        $.cookie('thecounter', thecounter, { path: '/' });
    }
    else
    {
        thecounter = $.cookie('thecounter');
    }

    $('dd-counter-num').html(thecounter);

    setTimeout(newtime, 5000);

});

function newtime () {

    var newtime = $.cookie('thecounter') + $.randomBetween(1, 2);
    $.cookie('thecounter', newtime, { path: '/' }); 
    $('dd-counter-num').html(newtime);
    setTimeout(newtime, 5000);

}
4

3 に答える 3

14

標準のjQuerycookieにはメソッドがありません。

おそらく、コードにはjquery-cookieまたは別のプラグインが必要ですか?

ハッピーコーディング。

于 2012-06-06T18:37:15.540 に答える
0

1) GitHub からこのプラグインをダウンロードします: https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js

2) スクリプト フォルダーに配置します。

3) ウェブサイトに含める:

<script src="~/Scripts/jquery.cookie.js" type="text/javascript"></script>

私のために働いた。

于 2013-05-24T03:40:58.987 に答える