js获取url传递参数
2024-10-14 14:17:32
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.onload = function() {
function GetURLlist(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r != null) return unescape(r[2]);
return null;
}
function GetUrlParam(paraName) {
var url = document.location.toString();
var arrObj = url.split("?");
if(arrObj.length > 1) {
var arrPara = arrObj[1].split("&");
var arr;
for(var i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("=");
if(arr != null && arr[0] == paraName) {
return arr[1];
}
}
return "";
}
else {
return "";
}
}
// 调用方法
console.log(GetURLlist("a"));
console.log(GetURLlist("b"));
console.log(GetURLlist("c"));
// 调用方法
console.log(GetUrlParam("a"));
console.log(GetUrlParam("b"));
console.log(GetUrlParam("c"));
}
</script>
</head>
<body>
</body>
设置或获取对象指定的文件名或路径。
alert(window.location.pathname)
设置或获取整个 URL 为字符串。
alert(window.location.href);
设置或获取与 URL 关联的端口号码。
alert(window.location.port)
设置或获取 URL 的协议部分。
alert(window.location.protocol)
设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)
设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)
设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)
最新文章
- 在 Linux 中安装 Oracle JDK 8 以及 JVM 的类加载机制
- 【转】 memcmp源码实现
- C#学习系列-String与string的区别
- C++ 中指针与引用的区别
- Leetcode Linked List Cycle II
- CHM文档打开空白的解决
- xamarin android——数据绑定到控件(二)
- Why your Games are Unfinished, and What To Do About It (转)
- BZOJ 2330: [SCOI2011]糖果( 差分约束 )
- [2011山东ACM省赛] Identifiers(模拟)
- GIT 版本控制命令学习
- 关于Vue问题记录
- 一个最简单的cell按钮点击回调
- webpack打包优化
- [已解决]Cannot find one or more components.Please reinstall the application
- 10;XHTML 其他标记
- HDFS笔记(一)
- Java并发编程-并发工具类及线程池
- nmon监控
- 浅谈js抽象工厂模式
热门文章
- linux获取系统启动时间
- ibatis XML标签的含义
- MVC concept
- [整理][LaTex]小技巧之——首行缩进
- Selenium2+python自动化25-js处理日历控件(修改readonly属性)
- Hdu OJ 5113 Black And White (2014ACM/ICPC亚洲区北京站) (搜索)
- 图解Android Studio导入Eclipse项目源码
- Java.web-application-development-environments-for-macosx
- AngularJs自定义指令详解(3) - scope
- html css 注释