这里是一个获取URL带REQUESTRING参数的JAVASCRIPT客户端解决方案,相当于asp的requestquerystring,PHP的$_GET,jsp的requestgetParameter
//var USERCODE="<%=requestgetParameter("USERCODE")%>";
//以上是用requestgetParameter在浏览器端获取参数值, 也可以是用该方法在服务器端获取参数方法
函数:
<Script language="javascript">
function GetRequest() {
var url = locationsearch; //获取url中""符后的字串
var theRequest = new Object();
if (urlindexOf("") != -1) {
var str = urlsubstr(1);
strs = strsplit("&");
for(var i = 0; i < strslength; i ++) {
theRequest[strs[i]split("=")[0]]=unescape(strs[i]split("=")[1]);
}
}
return theRequest;
}
</Script>
然后我们通过调用此函数获取对应参数值:
<Script language="javascript">
var Request = new Object();
Request = GetRequest();
var 参数1,参数2,参数3,参数N;
参数1 = Request['参数1'];
参数2 = Request['参数2'];
参数3 = Request['参数3'];
参数N = Request['参数N'];
</Script>
以此获取url串中所带的同名参数
二、正则分析法。function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&])(&|$)","i");
var r = windowlocationsearchsubstr(1)match(reg);
if (r!=null) return unescape(r[2]); return null;
}
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)