大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

jquery中如何使用session

小编给大家分享一下jquery中如何使用session,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

为企业提供网站设计、成都网站设计、网站优化、全网营销推广、竞价托管、品牌运营等营销获客服务。创新互联拥有网络营销运营团队,以丰富的互联网营销经验助力企业精准获客,真正落地解决中小企业营销获客难题,做到“让获客更简单”。自创立至今,成功用技术实力解决了企业“网站建设、网络品牌塑造、网络营销”三大难题,同时降低了营销成本,提高了有效客户转化率,获得了众多企业客户的高度认可!

在jquery中能用session,使用方法为:1、添加数据,代码为【$.session.set('key', 'value')】;2、删除数据,代码为【$.session.remove('key')】。

在jquery中能用session,使用方法为:

添加数据

$.session.set('key', 'value')

删除数据

$.session.remove('key');

获取数据

$.session.get('key');

清除数据

$.session.clear();

以下为jquery文件代码:新建复制即可使用

/** *说明:不可以获取java的session* 语法:添加数据$.session.set('key', 'value')
删除数据$.session.remove('key');
获取数据$.session.get('key');
清除数据$.session.clear();*/
(function($){
$.session = {
_id: null,
_cookieCache: undefined,
_init: function(){if (!window.name) {window.name = Math.random();}this._id = window.name;this._initCache();
// See if we've changed protcols
var matches = (new RegExp(this._generatePrefix() + "=([^;]+);")).exec(document.cookie);if (matches && document.location.protocol !== matches[1]) {this._clearSession();for (var key in this._cookieCache) {try {window.sessionStorage.setItem(key, this._cookieCache[key]);} catch (e) {};}}
document.cookie = this._generatePrefix() + "=" + document.location.protocol + ';path=/;expires=' + (new Date((new Date).getTime() + 120000)).toUTCString();
},
_generatePrefix: function(){return '__session:' + this._id + ':';},
_initCache: function(){var cookies = document.cookie.split(';');this._cookieCache = {};for (var i in cookies) {var kv = cookies[i].split('=');if ((new RegExp(this._generatePrefix() + '.+')).test(kv[0]) && kv[1]) {this._cookieCache[kv[0].split(':', 3)[2]] = kv[1];}}},
_setFallback: function(key, value, onceOnly){var cookie = this._generatePrefix() + key + "=" + value + "; path=/";if (onceOnly) {cookie += "; expires=" + (new Date(Date.now() + 120000)).toUTCString();}document.cookie = cookie;this._cookieCache[key] = value;return this;},
_getFallback: function(key){if (!this._cookieCache) {this._initCache();}return this._cookieCache[key];},
_clearFallback: function(){for (var i in this._cookieCache) {document.cookie = this._generatePrefix() + i + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';}this._cookieCache = {};},
_deleteFallback: function(key){document.cookie = this._generatePrefix() + key + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';delete this._cookieCache[key];},
get: function(key){return window.sessionStorage.getItem(key) || this._getFallback(key);},
set: function(key, value, onceOnly){try {window.sessionStorage.setItem(key, value);} catch (e) {}this._setFallback(key, value, onceOnly || false);return this;},'delete': function(key){return this.remove(key);},
remove: function(key){try {window.sessionStorage.removeItem(key);} catch (e) {};this._deleteFallback(key);return this;},
_clearSession: function(){try {window.sessionStorage.clear();} catch (e) {for (var i in window.sessionStorage) {window.sessionStorage.removeItem(i);}}},
clear: function(){this._clearSession();this._clearFallback();return this;}
};
$.session._init();
})(jQuery);

看完了这篇文章,相信你对jquery中如何使用session有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


当前标题:jquery中如何使用session
文章来源:http://dzwzjz.com/article/igscpp.html
在线咨询
服务热线
服务热线:028-86922220
TOP