string.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, "");} string.prototype.ltrim=function(){return this.replace(/(^\s*)/g,"");} string.prototype.rtrim=function(){return this.replace(/(\s*$)/g,"");} function parseurl(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 (; i < len; i++) { if (!seg[i]) { continue; } s = seg[i].split('='); ret[s[0]] = s[1]; } return ret; })(), file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1], hash: a.hash.replace('#', ''), path: a.pathname.replace(/^([^\/])/, '/$1'), relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1], segments: a.pathname.replace(/^\//, '').split('/') }; } //替换myurl中的同名参数值 function replaceurlparams(myurl, newparams) { for (var x in newparams) { var hasinmyurlparams = false; for (var y in myurl.params) { if (x.tolowercase() == y.tolowercase()) { myurl.params[y] = newparams[x]; hasinmyurlparams = true; break; } } //原来没有的参数则追加 if (!hasinmyurlparams) { myurl.params[x] = newparams[x]; } } var _result = myurl.protocol + "://" + myurl.host + ":" + myurl.port + myurl.path + "?"; for (var p in myurl.params) { _result += (p + "=" + myurl.params[p] + "&"); } if (_result.substr(_result.length - 1) == "&") { _result = _result.substr(0, _result.length - 1); } if (myurl.hash != "") { _result += "#" + myurl.hash; } return _result; }