試圖獲得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我想添加它,因爲這也幫助了我。 –