我使用jquery-cookie库来创建带有JQuery的cookie。如何更新cookie的值?我需要它创建新的cookie,如果cookie存在更新它。我该怎么做呢?我得到的代码如下:
v.on('click', function(){
var d = $(this).attr('role');
if(d == 'yes')
{
glas = 'koristan.'
}else {
glas = 'nekoristan.'
};
text = 'Ovaj komentar vam je bio ' + glas;
//This part here create cookie
if(id_u == 0){
$.cookie('010', id + '-' + d);
}
$.post('<?php echo base_url() ?>rating/rat_counter', {id : id, vote : d, id_u : id_u}, function(){
c.fadeOut('fast').empty().append('<p>' + text).hide().fadeIn('fast');
});
})发布于 2012-08-10 21:33:36
要更新cookie,您需要做的就是创建一个同名不同值的cookie。
编辑
将新的值附加到旧的值上...
//Im not familiar with this library but
//I assume this syntax gets the cookie value.
var oldCookieValue = $.cookie('010');
//Create new cookie with same name and concatenate the old and new desired value.
$.cookie('010', oldCookieValue + "-" + id);发布于 2012-08-10 21:36:12
请注意此链接
http://www.electrictoolbox.com/jquery-cookies/
在这里,您可以看到所有重要的事情,您可以使用cookies。
如果您想知道cookie是否已经存在,只需使用以下命令
if($.cookie("example") != null)
{
//cookie already exists
}https://stackoverflow.com/questions/11902737
复制相似问题