您的位置:首页 > 其它

url传参及windows.location相关属性说明

2014-08-15 16:23 260 查看
本节分享的这段jquery代码,用于获取当前页面url传递的参数。

代码如下:

view source

print?

01
/*--获取网页传递的参数--*/
02
function

request(paras)
03
{
04
var

url = location.href;
05
var

paraString = url.substring(url.indexOf(
"?"
)+1,url.length).split(
"&"
);
06
var

paraObj = {}
07
for

(i=0;j=paraString[i];i++){
08
paraObj[j.substring(0,j.indexOf(
"="
)).toLowerCase()]
= j.substring(j.indexOf(
"="
)+1,j.length);
09
}
10
var

returnValue = paraObj[paras.toLowerCase()];
11
if
(
typeof
(returnValue)==
"undefined"
){
12
return

""
;
13
}
else
{
14
return

returnValue;
15
}
16
}
调用此request即可,例如调用request("ID")。

附,windows.location相关属性及说明。

设置或获取对象指定的文件名或路径。

window.location.pathname

原文地址:http://www.jbxue.com/article/11659.html

设置或获取整个 URL 为字符串

window.location.href

设置或获取与 URL 关联的端口号码。

window.location.port

设置或获取 URL 的协议部分。

window.location.protocol

设置或获取 href 属性中在井号“#”后面的分段。

window.location.hash

设置或获取 location 或 URL 的 hostname 和 port 号码。

window.location.host

设置或获取 href 属性中跟在问号后面的部分。

window.location.search

window.location 属性 描述

hash 设置或获取

href 属性中在井号“#”后面的分段。

host 设置或获取 location 或 URL 的 hostname 和 port 号码。

hostname 设置或获取 location 或 URL 的主机名称部分。

href 设置或获取整个 URL 为字符串。

pathname 设置或获取对象指定的文件名或路径。

port 设置或获取与

URL 关联的端口号码。

protocol 设置或获取 URL 的协议部分。

search 设置或获取 href 属性中跟在问号后面的部分。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: