首页 > $g.$utils.实用工具类

$g.$utils.实用工具类

 

$g.$utils = {/**舒工Ajax-lite 1.0 -- 最精简的ajax自定义访问方法*/ajax: function (o) {var p = o.post, g = o.get, d = p.data, a = p.async, J = 'json', j = p[J], s = g.success, e = g.error;d = {async: a == undefined || a, /* false(解决手机端同步多次请求接口报错的问题)*/ timeout: 60000, type: p.type || "post", url: p.url, data: d, success: function (r) {s && s(r);}, error: function (r) {e && e(r);},};j ? (d.data = JSON.stringify(d.data), d.contentType = 'application/' + J) : (d.dataType = J), $.ajax(d);},hash: {get: function (win) {return decodeURIComponent((win || top).location.hash.substr(1));}, getSearchAndHash: function (win) {win || (win = top);return decodeURIComponent(win.location.search + win.location.hash);}, set: function (hash, win, isReload) {hash || (hash = "");win = win || top;win.location.hash = hash;isReload && win.location.reload();}, addListener: function (win) {(win || window).onhashchange = function () {this.location.reload();}}, getQueryString: function (name, win, isEncode) {var r = (win || top).location.search.substr(1).match(new RegExp("(^|&)" + name + "=([^&]*)(&|$)"));if (r != null) {return isEncode ? r[2] : decodeURIComponent(r[2]);}return null;}, parseQuery: function (url) {var reg = /([^=&s]+)[=s]*([^&s]*)/g, ls = url || location.search.substr(1), obj = {};while (reg.exec(ls)) {obj[RegExp.$1] = decodeURIComponent(RegExp.$2);}return obj;}, getToken: function () {return this.getQueryString("token")}, setUrlSearch: function (search, win, isReload) {  /**修改浏览器地址“?”后面(含?)的内容*//*此方法可以点击网页返回按钮*/win = win || top;win.history.pushState(null, null, search || "./");isReload && win.location.reload();}, replceUrlSearch: function (search, win, isReload) { /*此方法无网页返回按钮行为*/win = win || top;win.history.replaceState(null, null, search || "./");isReload && win.location.reload();}, getFileName: function () {var lp = location.pathname, fn = lp.substr(lp.lastIndexOf("/") + 1);return fn.substr(0, fn.lastIndexOf("."));}},/**绑定数据神器*/ bind: {set: function (h, l, v) {if (!h) return console.log("html传参为空", l, v);return h.replace(new RegExp("{" + l + "}", "g"), v).replace(new RegExp("\[" + l + "\]", "g"), v);}, object: function (h, o) {for (var a in o) var b = o[a], h = this.set(h, a, b);return h;}, a: function (html, obj) {return this.object(html, obj);}},/**去掉html标签(真正意义上去掉所有html标签包括内嵌的css样式)*/string: {stripHTML: function (str, isRemoveNewLine) {var t = document.createElement("div");t.innerHTML = str;document.querySelector("html").appendChild(t);var r = t.innerText;t.parentNode.removeChild(t);isRemoveNewLine && (r = r.replace(/[
]/g, ""));return r;},space: {/**去掉字符串前后空格*/trimSpace: function (str) {str || (str = '');return str.replace(/(^s*)|(s*$)/g, "");}, /**去掉字符串中所有空格(包括中间空格)*/trimAllSpace: function (str) {str || (str = '');return str.replace(/s+/g, "");}, /**去掉所有全角半角空格*/ trimAllWholeCornerSpace: function (str) {return str.replace(/ | /g, "")}, /**去掉所有全角半角 空格*/ trimAllWholeCornerCodeSpace: function (str) {return this.trimAllWholeCornerSpace(str).replace(/ /g, "");}},},screen: {/**实现F11全屏效果*/ fullScreen: function () {var docElm = document.documentElement;/*W3C*/if (docElm.requestFullscreen) {docElm.requestFullscreen();}/*FireFox */ else if (docElm.mozRequestFullScreen) {docElm.mozRequestFullScreen();}/*Chrome等 */ else if (docElm.webkitRequestFullScreen) {docElm.webkitRequestFullScreen();}/*IE11*/ else if (docElm.msRequestFullscreen) {docElm.msRequestFullscreen();}},/**退出F11全屏*/ exitFullScreen: function () {if (document.exitFullscreen) {document.exitFullscreen();} else if (document.mozCancelFullScreen) {document.mozCancelFullScreen();} else if (document.webkitCancelFullScreen) {document.webkitCancelFullScreen();} else if (document.msExitFullscreen) {document.msExitFullscreen();}},/**判断全屏模式是否是可用*/ isFullscreenEnabled: function () {return document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled || false;},/**判断整个页面被一个标签铺满*/ isFullscreenForNoScroll: function () {var explorer = window.navigator.userAgent.toLowerCase();if (explorer.indexOf('chrome') > -1) {/*webkit*/return (document.body.scrollHeight === window.screen.height && document.body.scrollWidth === window.screen.width);} else {/*IE 9+  fireFox*/return (window.outerHeight === window.screen.height && window.outerWidth === window.screen.width);}},/**判断是否全屏*/ isFullScreen: function () {return document.fullscreenElement || document.msFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement ? true : false;},/**实现局部div、dom元素全屏*/ fullScreenForDOM: function (sel) {sel = typeof sel == "string" ? document.querySelector(sel) : sel;/**el是具体的dom元素*/var rfs = sel.requestFullScreen || sel.webkitRequestFullScreen || sel.mozRequestFullScreen || sel.msRequestFullScreen, wscript;if (typeof rfs != "undefined" && rfs) {rfs.call(sel);return;}if (typeof window.ActiveXObject != "undefined") {wscript = new ActiveXObject("WScript.Shell");if (wscript) {wscript.SendKeys("{F11}");}}},/**实现局部div、dom元素退出全屏*/exitFullScreenForDOM: function (sel) {sel = typeof sel == "string" ? document.querySelector(sel) : sel;/**el是具体的dom元素*/var el = document, cfs = sel.cancelFullScreen || sel.webkitCancelFullScreen || sel.mozCancelFullScreen || sel.exitFullScreen, wscript;if (typeof cfs != "undefined" && cfs) {cfs.call(el);return;}if (typeof window.ActiveXObject != "undefined") {wscript = new ActiveXObject("WScript.Shell");if (wscript != null) {wscript.SendKeys("{F11}");}}},},
};

更多相关:

  •   /*禁止缩放safari浏览器*/ var scale = {disabledSafari: function () {/* 阻止双击放大*/var lastTouchEnd = 0;document.addEventListener("touchstart", function (event) {if (event.touch...

  •   Sg.js框架核心概念: 1)所有变量、方法、类对象全部都是从属于$g主树,由$g分支出很多$g.变量名、$g.方法、$g.对象id、$g.类;2)获取控件内部属性必须使用公开的get方法获取,禁止直接用访问内部变量方式来获取控件内部变量、属性值;3)修改控件内部属性、绑定方法等都必须使用公开的set方法来操作,禁止直接用访问...

  •  一、ios header导航栏被推起解决方法 1 设置弹出软键盘时自动改变webview的高度 plus.webview.currentWebview().setStyle({ softinputMode: "adjustResize" // 弹出软键盘时自动改变webview的高度 }); 2 增加样式 html...

  • 前端发送Ajax请求到服务器,服务器返回数据这一过程,因原因不同耗时长短也有差别,且这段时间内页面显示空白。如何优化这段时间内的交互体验,以及长时间内服务器仍未返回数据这一问题,是我们开发中不容忽视的重点。 常见的做法是: 1、设置超时时间,一旦时间超过设定值,便终止请求;2、页面内容加载之前,手动增加一个 loading 层。 代码...

  • /*判断屏幕宽高比是否为16:9*/ function isScreen16to9() {return window.screen.height / window.screen.width === 9 / 16; }...

  • /*关闭、刷新、跳转、离开当前网页前提示*/ onbeforeunload = function () {return false; };  ...

  • let json = {/**判断JSON格式*/ isJSON: function (str) {if (typeof str == "string") {try {var obj = JSON.parse(str);if (typeof obj == "object" && obj) {return true;} else {...

  •   项目结构   index.js //必须要安装否则就别想运行了❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤ //npm i body-parser -D & cnpm i express & cnpm i node-xlsx & cnp...

  • 一、递归 函数    为什么要有函数,提高代码的可读性,避免重复的代码,提高代码的复用性      在函数中能用return的不要print 1、递归的最大深度997 def foo(n):print(n)n+=1foo(n) foo(1) 递归的最大深度 2、修改递归的最大深度     由此我们可以看出,未报错之前能看到的最大数...