如何将dyanamic值存储到jQuery cookie变量中 [英] How to store dyanamic value into jquery cookie variable

查看:124
本文介绍了如何将dyanamic值存储到jQuery cookie变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can we store dynamic variables into cookie .

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

如何将变量用户名存储到jquery cookie变量中

how to store the variable username into jquery cookie variable

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

推荐答案

如果在单引号内放入字符串,则只需要使用字符串.因此,不需要单引号来分配值.

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.

尝试一下

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

对我有用.

这篇关于如何将dyanamic值存储到jQuery cookie变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆