"use strict"; var tools = { check_cookie:function(){ if(window.navigator.cookieEnabled) return true; else{ alert("浏览器配置错误,Cookie不可用!"); return false; } } ,set_cookie:function(name,value){ var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } ,get_cookie:function(name) { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return null; // var regexp = new RegExp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g"); // var result = regexp.exec(document.cookie); // return (result === null) ? null : result[1]; } ,del_cookie:function(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); } // 检测空对象 // 空则返回true ,isEmptyValue:function(value) { var type; if(value === null) { // 等同于 value === undefined || value === null return true; } type = Object.prototype.toString.call(value).slice(8, -1); switch(type) { case 'String': return !!$.trim(value); case 'Array': return !value.length; case 'Object': // return $.isEmptyObject(value); return !value.length; default: return false; } } ,isEmpty : function(v){ if (v instanceof String) { var r = /^\s*$/; return r.test(v); }else if(v instanceof Array){ return !v.length; }else if(v instanceof Object){ return v === {}; }else{ return false; } } ,is_set:function(value){ if (typeof(value) == "undefined") { return false; }else{ return true; } } // 解析URL路径 ,parseURL:function(url) { var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':',''), host: a.hostname, port: a.port, query: a.search, params: (function(){ var ret = [], seg = a.search.replace(/^\?/,'').split('&'), len = seg.length, i = 0, s; for (;iul>li>a ').each(function(index, el) { if ($(el).attr('href') !="#") { el.href+=location.search; }; }); }; // 对搜索分页的链接添加处理 if (!tools.isEmptyValue($('.pagination').toArray())){ $('.pagination>a ').each(function(index, el) { if ($(el).attr('href') !="#") { el.href+=location.search; }; }); }; // 验证码 $('input[name="captchas"]').one('focusin',function(e){ var img = $(this).nextAll('img.captchas'); if (tools.isEmptyValue(img)) { var imgStr = '