获取页面URL参数值


JavaScript


function GetParams(urlAddress) {
    var i, strLength, str, keyName, keyValue,
        params = {},
        url = document.getElementById('sf_debug').src;
    if (url.indexOf("?") > -1) {
        var index = url.indexOf("?");
        str = url.substring(index + 1);
        str = str.split("&")
        strLength = str.length;
        for (i = 0; i < strLength; i++) {
            var indexEqual = str[i].indexOf('=');
            keyName = str[i].substring(0, indexEqual);
            keyValue = str[i].substring(indexEqual + 1);
            if (keyName == "callback") keyValue = decodeURIComponent(keyValue);
            params[keyName] = keyValue;
        }
    }

    return params;
};

var getParams = new GetParams();

posted @ 2019-01-03 12:02  sfornt  阅读(504)  评论(0编辑  收藏  举报