我正在使用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');
});
})
Run Code Online (Sandbox Code Playgroud)
mar*_*ljn 12
要更新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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26906 次 |
| 最近记录: |