function trimLeft(str, key) { if(!str) return ""; if(!key) key = ' '; var index = 0; for (var i = 0; i < str.length; i++) if(str.charAt(i) == key){ index = i; break;} return str.substring(index, str.length); } function trimRight(str, key) { if(!str) return ""; if(!key) key = ' '; var index = str.length-1; for (var i = str.length-1; i >= 0; i--) if(str.charAt(i) == key){ index = i; break;} return str.substring(0, index+1); } function trim(str, key) { return trimLeft(trimRight(str, key), key); } var Util = { getCookie: function (name) { var cookieValue = ""; var arr; var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)){ cookieValue = decodeURI(arr[2]); if(!cookieValue){ cookieValue = localStorage.getItem(name); } } else cookieValue = localStorage.getItem(name); cookieValue = trim(cookieValue); return cookieValue; }, //鐧诲綍鎴愬姛鍚庝繚瀛樼敤鎴蜂俊鎭埌鏈湴鏁版嵁搴 setCookie: function (name, value, day) { // if (day !== 0) { //褰撹缃殑鏃堕棿绛変簬0鏃讹紝涓嶈缃甧xpires灞炴€э紝cookie鍦ㄦ祻瑙堝櫒鍏抽棴鍚庡垹闄 // var expires = day * 24 * 60 * 60 * 1000; // var date = new Date(+new Date() + expires); // document.cookie = name + "=" + encodeURI(value) + ";expires=" + date.toUTCString() + ';path=/;domain=zgsyb.com'; // } else { // document.cookie = name + "=" + encodeURI(value) + ';path=/;domain=zgsyb.com'; // } if (day !== 0) { //褰撹缃殑鏃堕棿绛変簬0鏃讹紝涓嶈缃甧xpires灞炴€э紝cookie鍦ㄦ祻瑙堝櫒鍏抽棴鍚庡垹闄 var expires = day * 24 * 60 * 60 * 1000; var date = new Date(+new Date() + expires); document.cookie = name + "=" + encodeURI(value) + ";expires=" + date.toUTCString() + ';path=/;domain=zgsyb.com'; localStorage.setItem(name, value); } else { document.cookie = name + "=" + encodeURI(value) + ';path=/;domain=zgsyb.com'; localStorage.setItem(name, value); } }, //鍒犻櫎cookie delCookie: function (name) { Util.setCookie(name, ' ', -1); localStorage.removeItem(name); }, //鎻愬彇url涓殑鍩熷悕 getDomain: function(url) { var domain = url.split('/'); if(domain[2]) { domain = domain[2]; } else { domain = ''; //濡傛灉url涓嶆纭氨鍙栫┖ } return domain; } }