URL参数解析

1、
function analyticParameter(){
    var URL = document.location.toString();
    if(URL.lastIndexOf("?")!=-1){
        var QueryString= URL.substring(URL.lastIndexOf("?")+1,URL.length);
        var tmpArr1=QueryString.split(",");
        var tmpArrs=tmpArr1[0].split("=");
        if(tmpArrs[0]=="jzdm"){
            jzStationName =parseInt(decodeURI(tmpArrs[1]));
        }
        else{
            jzStationName = null;
        }
    }
    else{
        jzStationName = null;
    }
}

2、
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;
}

var username = decodeURI(GetQueryString("username"));

你可能感兴趣的:(JS参考实例,JS,JS学习笔记)