正则匹配
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; }
调用方法:
var v = GetQueryString("参数名1");
数组分割的方法:
function getUrlParam(name) { var url = unescape(window.location.href); var allargs = url.split("?")[1]; var args = allargs.split("&"); for (var i = 0; i < args.length; i++) { var arg = args[i].split("="); if ((name.toLocaleLowerCase()) == (arg[0].toLocaleLowerCase())) { return arg[1]; } } }