Topic: 得到WEB URL请求后的参数变量值的Javascript函数

  Print this page

1.得到WEB URL请求后的参数变量值的Javascript函数 Copy to clipboard
Posted by: Happy漫步者
Posted on: 2009-08-26 09:59

function getParam(p){
var p1 = {};
var p2 = location.href.match(/[^s&?=/#]+=[^s&?=/#]+/g);
if(p2){
for(var i = 0, l = p2.length; i < l; i++){var n = p2[i].split("=");p1[n[0]] = n[1];}
}
return ( typeof(p1[p]) == "undefined" )?'':p1[p];
}

运行Demo 的GET请求
http://www.txdnet.cn/data/file/GetParam/20090813215614359496.html?param=HelloWorld
页面引入getParam()函数后,使用

alert(getParam('param'));

欢迎网友完善该函数,并及时邮件告诉我 email:txdnet@gmail.com

http://www.txdnet.cn/essay/view.jsp?tid=1250171576656&cid=2


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923