js获取当前url的参数

<scripttype="text/javascript">

/*取得当前url的参数

* paras:参数名

* 例子: www.163.com?id=1234&pw=5678

* var id = request('id') //1234

* var pw = request('ps') //5678

* 作者:夏雨

*/

function request(paras,url){

if(typeof url == "undefined" || url== ''){

url = location.href;

}

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

var paraObj = {}

for (i=0; j=paraString[i]; i++){

paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);

}

var returnValue = paraObj[paras.toLowerCase()];

if(typeof(returnValue)=="undefined"){

return"";

}else{

return returnValue;

}

}

</script>

 

你可能感兴趣的:(url)