首页 > Web开发 > 详细

JS 获取URL 后面的参数

时间:2019-07-26 18:37:59      阅读:81      评论:0      收藏:0      [点我收藏+]
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]);
                }
            }

            if (theRequest == undefined || theRequest == null) {
                theRequest == "";
            }

            return theRequest;
        } 
        
        
        
        
        
        
        
        
        
        
        
        //解决中文乱码
         function getParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null)
                        return decodeURI(r[2]);   //对参数进行decodeURI解码
                return null;
           
        }
        
        
        https://localhost:5001/script/selectbox/template/tableItem.html?nos%20=JT201600723&date=2016-10&company=母公司&curreny=人民币(CNY)&status=已审计&wd=实际
        
        
        
        %20  为空格  传参的时候注意点即可

JS 获取URL 后面的参数

原文:https://www.cnblogs.com/imtudou/p/11251957.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!