javascript

推荐列表 站点导航

当前位置:首页 > 脚本编程 > javascript >

在jquery中能用session吗

来源:网络整理  作者:  发布时间:2020-12-19 01:24
在jquery中能用session,使用方法为:1、添加数据,代码为【$.session.set(...

/** *说明:不可以获取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=https://www.ym97.com/;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=https://www.ym97.com/";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=https://www.ym97.com/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';}this._cookieCache = {};}, _deleteFallback: function(key){document.cookie = this._generatePrefix() + key + '=; path=https://www.ym97.com/; 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吗

$.session.get('key');

清除数据

$.session.clear();

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

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

删除数据

添加数据

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

$.session.remove('key');

获取数据

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

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

相关热词: jquery

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/jiaob/javascript/5394.shtml

最新文章
Javascript是什么? Javascript是什么?

时间:2021-01-04

Canvas入门实战之实现一个 Canvas入门实战之实现一个

时间:2021-01-04

11月份GitHub上最热门的Ja 11月份GitHub上最热门的Ja

时间:2021-01-04

一篇带给你JavaScript的Cla 一篇带给你JavaScript的Cla

时间:2021-01-04

详解js异步文件加载器 详解js异步文件加载器

时间:2021-01-04

深入理解JavaScript中的箭头 深入理解JavaScript中的箭头

时间:2021-01-04

复盘Node项目中遇到的13+常 复盘Node项目中遇到的13+常

时间:2021-01-04

连续3年稳居第一,全球 连续3年稳居第一,全球

时间:2021-01-04

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

在jquery中能用session吗

2020-12-19 编辑:

/** *说明:不可以获取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=https://www.ym97.com/;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=https://www.ym97.com/";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=https://www.ym97.com/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';}this._cookieCache = {};}, _deleteFallback: function(key){document.cookie = this._generatePrefix() + key + '=; path=https://www.ym97.com/; 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吗

$.session.get('key');

清除数据

$.session.clear();

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

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

删除数据

添加数据

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

$.session.remove('key');

获取数据

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

本教程操作环境:windows7系统、jquery3.2.1版本,该方法适用于所有品牌电脑。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/jiaob/javascript/5394.shtml

相关文章

风云图片

推荐阅读

返回javascript频道首页