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

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

 更新時(shí)間:2010年06月12日 21:39:02   作者:  
在外國一博客看到一個(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)論

巴东县| 新昌县| 衢州市| 千阳县| 苍山县| 维西| 宣城市| 石嘴山市| 鹿邑县| 湛江市| 盐津县| 东乌| 灯塔市| 缙云县| 梧州市| 文昌市| 金川县| 子洲县| 垫江县| 威宁| 仁布县| 罗江县| 泗水县| 新沂市| 阿城市| 全南县| 和平区| 正宁县| 师宗县| 光泽县| 成安县| 百色市| 扎赉特旗| 垣曲县| 纳雍县| 荆门市| 阜阳市| 霸州市| 揭东县| 曲周县| 田东县|