1.unicode编码转中文 例如‘送的发送到’
G.globalHtmlCharDecode = function(obj) { var type = function(obj) { return Object.prototype.toString.call(obj); }, isString = function(obj) { return type(obj) === '[object String]' }, isObj = function(obj) { return type(obj) === '[object Object]' }, isArr = function(obj) { return type(obj) === '[object Array]' }, decode = function(str) { var div = document.createElement('div') div.innerHTML = str; str = div.innerText; div = null; return str; }, objFn = function(origin, target) { for ( var i in origin) { // if(Object.hasOwnProperty(i)) oi = origin[i]; if (i.indexOf('&#') > -1) { i = decode(decode(i)) } target[i] = oi; if (isString(oi) && oi.indexOf('&#') > -1) { target[i] = decode(decode(oi)) } else if (isObj(oi) || isArr(oi)) { objFn(oi, target[i] = (isObj(oi) ? {} : [])) } } return target; } if (isObj(obj) || isArr(obj)) { obj = objFn(obj, isObj(obj) ? {} : []); } else if (isString(obj)) { obj = decode(obj) } else { // throw new Error('globalHtmlCharDecode params error') } return obj; }浏览器url截取如果中文 类似 %3e%%dd%
this.appsubname = decodeURIComponent(G.getUrlParam('str'));截取url参数
//获取参数 G.getUrlParam = function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return ''; }