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; } // 获取url参数: // var arg1 = GetQueryString(‘param1‘); // var arg2 = GetQueryString(‘param2‘);
另外一种方法:
function getUrlParam(name) { var arg = location.search; if (arg.indexOf(‘?‘) !== -1) { var str = arg.substr(1).split(‘&‘); var argObj = new Object(); for (var i = 0; i < str.length; i++) { argObj[str[i].split(‘=‘)[0]] = unescape(str[i].split(‘=‘)[1]); } } return argObj[name]; } // 获取url参数: // var arg1 = getUrlParam(‘param1‘); // var arg2 = getUrlParam(‘param2‘);
时间: 2024-10-10 13:27:08