cố gắng lấy giá trị cookie
nếu thiết lập và cập nhật div
với cookie
giá trị, nếu không tạo ra một số ngẫu nhiên giữa 80-100, thiết lập đó là cookie
, và sau đó cập nhật div
.Chức năng đối tượng (a, b) {return new e.fn.init (a, b, h)} không có phương pháp 'cookie'
im nhận được lỗi:
Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie'
heres mã của tôi:
$(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);
}
Có vẻ như đây là plugin bạn đang tìm kiếm: https://github.com/carhartl/jquery-cookie Có thể tôi đã thêm nó vì điều này cũng giúp ích cho tôi. –