jquery session - 动态变量命名
只是这里有问题。 我正在使用 jquery、css 制作基于网络的应用程序的 UI。 有一个购物车,我想将所选项目存储在会话中,我使用了 jquery.session 插件。 例如 var $.session("var1","item1");
我想要的是将项目动态存储到动态命名的变量中。 我怎么能那样做呢?
谢谢。
just having a problem here.
i'm doing the UI of a web-based app using jquery, css.
there's a shopping a cart, and i want to store the selected items in the session, i used jquery.session plugin.
e.g. var $.session("var1","item1");
What i want is to dynamically store items into dynamically named variables.
how could i do that?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果有购物车,则该数据应该由服务器端脚本语言(例如 PHP)处理。 我假设最后他们会通过信用卡收费? 此类数据需要安全。
此外,这是由非安全客户端语言(例如 JS)处理的相当大的功能,可以将其关闭。
只是未来要考虑的事情..
If there's a shopping cart, that data should be handled by a server side scripting language like PHP. I'm assuming at the end they will be charged via credit card? This kind of data needs to be secure.
In addition, that's a pretty big part of functionality to be handled by a non-secure client-side language like JS that can be turned off.
Just something to think about in the future..
一种方法是创建一个存储“会话”变量的函数。 会话有两个参数:变量名及其值。 例如:
每当您需要设置 jQuery 会话变量时,只需调用该函数,如下所示:
One way that you could do that is to create a function that stores the 'session' variables. The session would have two parameters, the variable name and its value. For example:
Whenever you need to set the jQuery session variable, just call the function as in:
只需使用字符串将其构建为您想要的内容,如下所示:
您还可以在元素上存储任意数据并使用它们,如下所示:
The above loops through each element with the vote_action class set. On each element it finds it gets the id attribute, which is a string like action_NN, and then chops off the action part. Then it stores this vote_id as arbitrary data on the element under the "vote_id" name.
Just use strings to build it up to what you want, like so:
You can also store arbitrary data on elements and use them, like so:
The above loops through each element with the vote_action class set. On each element it finds it gets the id attribute, which is a string like action_NN, and then chops off the action part. Then it stores this vote_id as arbitrary data on the element under the "vote_id" name.
由于会话函数将字符串作为参数,因此只需动态创建这些字符串即可。
Since the session function takes strings as parameters, just create these strings dynamically.