How to store dyanamic value into jquery cookie variable

让人想犯罪 __ 提交于 2020-01-03 02:51:06

问题


How can we store dynamic variables into cookie .

var username = ($("#username").val());

how to store the variable username into jquery cookie variable

$.cookie('username', '+username +');
alert($.cookie('username'));

回答1:


If you put within a single quotes it takes only string.So for this you don't need the single quotes for assigning the value.

Try this

$(document).ready(function() {
    var username = ($("#username").val());
    $.cookie('username', username ); 
    alert($.cookie('username'));  
});

It works for me.



来源:https://stackoverflow.com/questions/3758180/how-to-store-dyanamic-value-into-jquery-cookie-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!