js获取url 参数

 window.getRequest = function (url) {
        var theRequest = new Object();
        var indexOf = url.indexOf("?");
        if (indexOf > -1) {
            var str = url.substr(indexOf + 1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    };

调用代码

 var str = getRequest("http://ShsbView.html?S_ID=xx&U_ID=zz");

 

posted @ 2015-06-25 11:35  刘小吉  阅读(319)  评论(1编辑  收藏  举报