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

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

函數(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'

演示代碼:

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

JavaScript技術(shù)javascript parseUrl函數(shù)(來(lái)自國(guó)外的獲取網(wǎng)址url參數(shù)),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 唐山市| 沁阳市| 安仁县| 旌德县| 女性| 丹江口市| 时尚| 天水市| 溧阳市| 和龙市| 米泉市| 马关县| 蒲江县| 万安县| 建昌县| 普宁市| 南雄市| 闻喜县| 廉江市| 彭阳县| 新密市| 阳朔县| 博湖县| 普兰店市| 南靖县| 海门市| 和林格尔县| 古浪县| 会宁县| 琼海市| 丹阳市| 疏勒县| 海南省| 吴旗县| 铅山县| 荣成市| 若羌县| 东乡族自治县| 旬邑县| 米泉市| 临夏县|