色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript parseUrl函數(來自國外的獲取網址url參數)

函數代碼
復制代碼 代碼如下:
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('/')
};
}

用法:
復制代碼 代碼如下:
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'

演示代碼:

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]

JavaScript技術javascript parseUrl函數(來自國外的獲取網址url參數),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 定南县| 南涧| 偏关县| 大宁县| 酉阳| 平邑县| 峨眉山市| 江陵县| 塘沽区| 方山县| 共和县| 吴桥县| 遵义市| 遵化市| 津市市| 玛纳斯县| 巴中市| 莱阳市| 延庆县| 永平县| 禹州市| 黄平县| 丹凤县| 雷山县| 册亨县| 潮安县| 峨山| 贺州市| 临邑县| 蒲江县| 武川县| 吴川市| 鄯善县| 鹤岗市| 南城县| 五指山市| 肇庆市| 桃园县| 随州市| 奉化市| 揭东县|