最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript parseUrl函數(shù)(來(lái)自國(guó)外的獲取網(wǎng)址url參數(shù))

 更新時(shí)間:2010年06月12日 21:39:02   作者:  
在外國(guó)一博客看到一個(gè)很好的函數(shù),獲取網(wǎng)址url等地址參數(shù)。非常不錯(cuò),值得參考與收藏。
函數(shù)代碼
復(fù)制代碼 代碼如下:

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('/')
};
}

用法:
復(fù)制代碼 代碼如下:

var myURL = parseURL('http://abc.com:8080/dir/index.html?id=255&m=hello#top');
myURL.file; // = 'index.html'
myURL.hash; // = 'top'
myURL.host; // = 'abc.com'
myURL.query; // = '?id=255&m=hello'
myURL.params; // = Object = { id: 255, m: hello }
myURL.path; // = '/dir/index.html'
myURL.segments; // = Array = ['dir', 'index.html']
myURL.port; // = '8080'
myURL.protocol; // = 'http'
myURL.source; // = 'http://abc.com:8080/dir/index.html?id=255&m=hello#top'

演示代碼:

相關(guān)文章

最新評(píng)論

洛浦县| 胶南市| 黔东| 通州市| 平安县| 马鞍山市| 双鸭山市| 尖扎县| 石家庄市| 水城县| 马关县| 三河市| 柘城县| 烟台市| 凤城市| 桃江县| 宁夏| 桂林市| 贺兰县| 成安县| 漯河市| 剑川县| 荆州市| 米易县| 蓬莱市| 淮安市| 涞源县| 正定县| 四平市| 家居| 兰溪市| 嘉善县| 秀山| 临邑县| 秦皇岛市| 措勤县| 靖远县| 固始县| 长岭县| 宕昌县| 儋州市|