web前端|js教程
parseUrl,网址,url参数
web前端-js教程
函数代码
展柜官网源码,vscode活动怎样显示,ubuntu 左侧 取消,tomcat改网站名字,sqlite数据库自动增长,主题爬虫主要使用在哪些场合,php程序员成长,seo优化定制官网,模块化网站源码,电子商务网站模板源码lzw
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(/)
};
}
用法:
asp手机商城源码,vscode源码检查,ubuntu板子,tomcat 部署404,json写入sqlite3,wordpress侧面导航插件,前端学哪个框架比较好,爬虫在手机上怎么用,php 生成表格,seo最先做什么,苹果cms视频解析网站源码,外贸网页展示源代码,织梦模板安装文件在哪lzw
var myURL = parseURL(:8080/dir/index.html?id=255&m=hello#top);
myURL.file; // = index.html
myURL.hash; // = op
myURL.host; // = \
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; // = :8080/dir/index.html?id=255&m=hello#top
演示代码:
免费ip提取网站源码,mi3 ubuntu,jdk9的tomcat,骷髅爬虫蜥蜴,php爬取视频,垫江专业性seo推广大概多少钱lzw
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(:8080/dir/index.html?id=255&m=hello#top); alert(myURL.file); // = index.html myURL.hash; // = op myURL.host; // = \ 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; // = :8080/dir/index.html?id=255&m=hello#top
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
如果觉得《javascript parseUrl函数(来自国外的获取网址url参数)【javascript】》对你有帮助,请点赞、收藏,并留下你的观点哦!