为什么 window.location.search 为空?
来源:互联网 发布:mac os x系统镜像下载 编辑:程序博客网 时间:2024/05/10 05:51
1,什么是window.location?示例
URL:http://b.a.com:88/index.php?name=kang&when=2011#first
window.location和document.location互相等价的,可以交换使用
location的8个属性都是可读写的,但是只有href与hash的写才有意义。例如改变location.href会重新定位到一个URL,而修改location.hash会跳到当前页面中的anchor(<a id="name">或者<div id="id">等)名字的标记(如果有),而且页面不会被重新加载
注意
URL:http://b.a.com:88/index.php?name=kang&how=#when=2011#first
hash:"#when=2011#first" 第一个"#"之后的内容
2,为什么 window.location.search 为空?
答:注意上面的search和hash的区别,如果URL中“?”之前有一个“#”比如:“http://localhost:63342/index.html#/version?type=35&id=5”那么使用window.location.search得到的就是空(“”)。因为“?type=35&id=5”串字符是属于“#/version?type=35&id=5”这个串字符的,也就是说查询字符串search只能在取到“?”后面和“#”之前的内容,如果“#”之前没有“?”search取值为空。
3,应用
1 //获取url参数 2 function GetQueryString (name) 3 { 4 var after = window.location.hash.split("?")[1]; 5 if(after) 6 { 7 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 8 var r = after.match(reg); 9 if(r != null)10 {11 return decodeURIComponent(r[2]);12 }13 else14 {15 return null;16 }17 }18 }
阅读全文
0 0
- 为什么 window.location.search 为空?
- 为什么 window.location.search 为空?
- window.location.search是什么意思
- window.location.search是什么意思
- window.location.search用法
- window.location.search
- 初识window.location.search
- window.location.search
- window.location.Search的用法
- window.location.search的用法
- window.location.search的用法
- window.location.search的用法
- window.location.search的用法
- window.location.search的用法
- Android location对象为空
- javascript中的window.location.search方法
- js 中的window.location.search.match("XX")
- window.location.search.substring(1); 什么意思
- mt2523 [keypad]how to config keydata mapping with GPIO pin?
- Charles青花瓷安装使用及断点设置
- QPainterPath
- Java对象名称解释
- jdbc:oracle:thin:@192.168.3.98:1521:orcl(详解)
- 为什么 window.location.search 为空?
- adb 常用命令
- Java数据类型
- 使用IntelliJ IDEA配置Erlang开发环境
- “http://hao643.com/?r=wwwww&m=c166” 类似这样的恶意链接去除方法
- 2016 CCF大数据与计算智能大赛 开源资料整理
- druid数据库连接池
- yii2.0如何使用ActionForm
- windows 安装Python的networkx