js 获取 url 参数

js 获取 url 参数

    <script type="text/javascript">
        //var url = parent.location.search;
        var url = " http://www.abc.com.cn/index.asp?aa=1&bb=2&cc=3";
        var request = new Object();
        if (url.indexOf("?") != -1)// 参数前的地址
        {
            var str = url.substr(url.indexOf("?") + 1);
            var items = str.split("&");
            for (var i = 0; i < items.length; ++i) {
                request[items[i].split("=")[0]] = unescape(items[i].split("=")[1]);
            }
        }

        console.log(request['aa']);
        console.log(request['bb']);
        console.log(request['cc']);
    </script>


热门推荐