首页 > 代码库 > JS 操作Url参数

JS 操作Url参数

项目中需要JS操作路径参数,小弟不才,不跳会,因此查了一下,总结一下使用方法

<script type="text/javascript">    //运用    window.onload = function () {        var Request = new Object();        Request = GetRequest();        var urlPara = Request[‘isChecked‘];        if (urlPara != null && urlPara != "") {            if (urlPara.indexOf("rad") > -1) {                SelectRadio(urlPara);            }        }    }    // 判断选中    function SelectRadio(id) {        //debugger;        document.getElementById(id).checked = true;    }    //获取url参数    function GetRequest() {        var url = location.search; //获取url中"?"符后的字串        var theRequest = new Object();        if (url.indexOf("?") != -1) {            var str = url.substr(1);            strs = str.split("&");            for (var i = 0; i < strs.length; i++) {                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);            }        }        return theRequest;    }</script>