js 利用 a 标签解析 URL
<script>
function parseURL(url){
var a = document.createElement("a");
a.href = url;
return {
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;
/**
var q={};location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);
return q;
* **/
})(),
hash:a.hash.replace("#","")
}
}
console.log(parseURL("http://192.168.10.6:9993/index?index=2&tag=11"));
</script>