js接收参数几种方式


 方式1:
  var request = {
            QueryString: function (val) {
                var uri = window.location.search;
                var re = new RegExp("" + val + "\=([^\&\?]*)", "ig");
                return ((uri.match(re)) ? (uri.match(re)[0].substr(val.length + 1)) : null);
            }
        }
   // 获取参数
            var edunitID = request.QueryString("EDUUnitID"); //学校id
            var SemesterID = request.QueryString("SemesterID"); //学年学期id
            var GradeID = request.QueryString("GradeID"); //年级id

方式2:
  //获取url参数
        function request(strParame) {
            var args = new Object();
            var query = location.search.substring(1);
            var pairs = query.split("&");
            for (var i = 0; i < pairs.length; i++) {
                var pos = pairs[i].indexOf('=');
                if (pos == -1) { continue; }
                var argname = pairs[i].substring(0, pos);
                var value = pairs[i].substring(pos + 1);
                value = decodeURIComponent(value);
                args[argname] = value;
            }
            return args[strParame];
        }
方式3:
  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;
        }


  var Request = new Object();
            Request = GetRequest();
            if (Request['ctfid'] != undefined) {
                ctfid = Request['ctfid']; //组合id
            }

 

你可能感兴趣的:(【JS】Javascript,JavaScript,接收参数)