function
GetQueryString(name)
{
var
reg =
new
RegExp(
"(^|&)"
+ name +
"=([^&]*)(&|$)"
);
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"
));
若地址栏URL为:abc.html?id=123&url=http://www.maidq.com
那么,当你用上面的方法去调用:alert(GetQueryString("url"));
则会弹出一个对话框:内容就是 http://www.maidq.com
如果用:alert(GetQueryString("id"));那么弹出的内容就是 123 啦;
当然如果你没有传参数的话,强行输出调用结果有的时候会报错:
参考:http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html
-----------------------------------------------------------------------------------------------------------------------------------
实例:
传参:
var deId = $("#deId").val();
var deName = $("#deName").val();
location.href = "http://localhost:3207/MemberMgr/WashCar.html?deId=" + deId + "&deName=" + encodeURI(deName);//解决中文乱码
接收:
$(function () {
GetQueryString("deId");
GetQueryString("deName");
});
//截取url的参数
function GetQueryString(parameter) {
var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
if (parameter == "deId") {
$("#deId").val(r[2]);
}
if (parameter == "deName") {
$("#deName").val(decodeURI(r[2]));//解决中文乱码
}
}
}
-----------------------------------------------------------------------------------------------------------------