Javascript获取url中的参数

function GetUrlParms(parmsName) {
var parms = window.location.href.split('?')[1];
if (parms == null || parms == "")
return;
var arr = parms.split('&');

if (arr.length > 1) {
for (var i = 0; i < arr.length; i++) {
var name = arr[i].substring(0, arr[i].indexOf("="));
if (name == parmsName) {
var begin = arr[i].indexOf("=");
var end = arr[i].length;
alert(arr[i].substring(begin + 1, end));
return arr[i].substring(begin + 1, end);
}
}
} else {
var begin = parms.indexOf("=");
var end = parms.length;
alert(parms.substring(begin + 1, end));
return parms.substring(begin + 1, end);
}
}
posted @ 2012-03-13 13:58  lanmiao  阅读(134)  评论(0编辑  收藏  举报