1.通过GET方法用URL地址传递参数。
1 function GetQueryString(name) {
2 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
3 var r = window.location.search.substr(1).match(reg);
4 if (r != null) return unescape(r[2]); return null;
5 }
6
7
8 调用方法:
9 alert(GetQueryString("参数名1"));
1 var url = window.location;
2 function getUrlParam(url, name) {
3 var pattern = new RegExp("[?&]" + name + "=([^&]+)", "g");
4 var matcher = pattern.exec(url);
5 var items = null;
6 if (matcher != null) {
7 try {
8 items = decodeURIComponent(decodeURIComponent(matcher[1]));
9 } catch (e) {
10 try {
11 items = decodeURIComponent(matcher[1]);
12 } catch (e) {
13 items = matcher[1];
14 }
15 }
16 }
17 return items;
18 }
调用方法:
var id = getUrlParam(url, 'id');