-
-
Save antife-yinyue/f343ee282bc1ea415f9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = function(url) { | |
var a = document.createElement('a'); | |
a.href = url; | |
var search = function(search) { | |
if(!search) return {}; | |
var ret = {}; | |
search = search.slice(1).split('&'); | |
for(var i = 0; i < search.length; i++) { | |
var n = search[i].indexOf('='); | |
var key, val; | |
if (n === -1) { | |
key = search[i]; | |
val = null; | |
} | |
else { | |
key = search[i].substring(0, n); | |
val = search[i].substring(n + 1); | |
} | |
ret[key] = val; | |
} | |
return ret; | |
}; | |
return { | |
protocol: a.protocol, | |
host: a.host, | |
hostname: a.hostname, | |
pathname: a.pathname, | |
search: search(a.search), | |
hash: a.hash | |
} | |
}; | |
var url = 'http://sub.example.com:8023/home/?foo=bar&ciao=cc#hash'; | |
parser(url); | |
// 结果是? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
还没有支持 数组,在开会,不写了