1. 程式人生 > >獲取頁面URL引數值

獲取頁面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();