jquery - 如何将动态值存储到jquery cookie变量中

标签 jquery html cookies dhtml

我们如何将动态变量存储到 cookie 中。

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

如何将变量 username 存储到 jquery cookie 变量中

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

最佳答案

如果您将其放在单引号内,则仅需要字符串。因此,您不需要使用单引号来分配值。

试试这个

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

这对我有用。

关于jquery - 如何将动态值存储到jquery cookie变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3758180/

相关文章:

javascript - Highcharts问题: variable legend height

jquery - 防止 bootstrap 崩溃动画高于 md 断点

jquery - 在小屏幕上重新排列容器位置的流体布局

html - 全高 - Web 响应 - Twitter Bootstrap

php 检查 session 是否足够安全?

javascript - 将 jQuery ajax 转换为 fetch

jquery - 动态添加图像到 Canvas

IE7 上的 JQuery 方法 .before() 或 .insertBefore()

security - 确保基于 Cookie 的身份验证安全

google-chrome - 当我从检查器中设置Cookie时,Chrome为什么将我的cookie涂成红色?