jQuery jquery中的会话处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11580172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
session handling in jquery
提问by user1206218
I am using following code to store value in session object in jQuery but i get error $.session function is not a function.
我正在使用以下代码在 jQuery 中的会话对象中存储值,但出现错误 $.session 函数不是函数。
I also add plugin "jquery.session.js" from githhub site but it is not work. Pls let me help out what's wrong
我还从 Githhub 站点添加了插件“jquery.session.js”,但它不起作用。请让我帮忙看看有什么问题
// To Store
$(function() {
$.session("myVar", "value");
});
// To Read
$(function() {
alert( $.session("myVar") );
});
If there is any other way to do this...then also tell me.....
如果有任何其他方法可以做到这一点...然后也告诉我.....
回答by Frédéric Hamidi
Assuming you're referring to this plugin, your code should be:
假设你指的是这个插件,你的代码应该是:
// To Store
$(function() {
$.session.set("myVar", "value");
});
// To Read
$(function() {
alert($.session.get("myVar"));
});
Before using a plugin, remember to read its documentationin order to learn how to use it. In this case, an usage example can be found in the README.markdown
file, which is displayed on the project page.
在使用插件之前,请记住阅读其文档以了解如何使用它。在这种情况下,可以在README.markdown
文件中找到使用示例,该文件显示在项目页面上。
回答by ktamlyn
In my opinion you should not load and use plugins you don't have to. This particular jQuery plugin doesn't give you anything since directly using the JavaScript sessionStorage
object is exactly the same level of complexity. Nor, does the plugin provide some easier way to interact with other jQuery functionality. In addition the practice of using a plugin discourages a deep understanding of how something works. sessionStorage should be used only if its understood. If its understood, then using the jQuery plugin is actually MORE effort.
在我看来,您不应该加载和使用不需要的插件。这个特殊的 jQuery 插件不会给你任何东西,因为直接使用 JavaScriptsessionStorage
对象的复杂程度完全相同。插件也没有提供一些更简单的方式来与其他 jQuery 功能进行交互。此外,使用插件的做法不利于深入了解某些东西是如何工作的。sessionStorage 只有在理解时才应该使用。如果理解,那么使用jQuery插件实际上是更多的努力。
Consider using sessionStorage
directly:
https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#sessionStorage
考虑sessionStorage
直接使用:https:
//developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#sessionStorage