试图获得cookie
的值,如果它设置并更新div
与cookie
值,否则生成80-100之间的随机数,将其设置为cookie
,然后更新div
。对象函数(a,b){return new e.fn.init(a,b,h)}没有方法'cookie'
即时得到错误:
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);
}
看起来像这是你正在寻找的插件:https://github.com/carhartl/jquery-cookie我想添加它,因为这也帮助了我。 –