javascript实现页面跳转功能,参数怎么传递? 10
1个回答
展开全部
方法一:正则分析法
function getQueryString(name) { //输入参数名称
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); //根据参数格式,正则表达式解析参数
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null; //返回参数值
}
调用方法:
alert(GetQueryString("参数名1"));alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
方法二
<Script language="javascript">
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&"); //根据&解析所有参数key=value
for(var i = 0; i < strs.length; 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>
function getQueryString(name) { //输入参数名称
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); //根据参数格式,正则表达式解析参数
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null; //返回参数值
}
调用方法:
alert(GetQueryString("参数名1"));alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
方法二
<Script language="javascript">
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&"); //根据&解析所有参数key=value
for(var i = 0; i < strs.length; 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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询