ocation.search是从当前URL的?号开始的字符串
如:http://www.51js.com/viewthread.php?tid=22720 javascript
它的search就是?tid=22720 php
eg:java
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r)
return decodeURIComponent(r[2]);
}函数
decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。ui
在本例中,咱们将使用 decodeURIComponent() 对编码后的 URI 进行解码:编码
<script type="text/javascript">
var test1="http://www.w3school.com.cn/My first/"
document.write(+ "<br />")
document.write()
</script>encodeURIComponent(test1)decodeURIComponent(test1)
输出:spa
http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F http://www.w3school.com.cn/My first/
参考:code
http://shirlly.iteye.com/blog/385361blog
http://www.w3school.com.cn/jsref/jsref_decodeURIComponent.aspip