The following code is used to obtain the request Parameters in JavaScript in the tutorial www.bkjia.com:
Copy to ClipboardReference: [www.bkjia.com] UrlParm = function () {// url parameter
Var data, index;
(Function init (){
Data = [];
Index = {};
Var u = window. location. search. substr (1 );
If (u! = ''){
Var parms = decodeURIComponent (u). split ('&');
For (var I = 0, len = parms. length; I <len; I ++ ){
If (parms [I]! = ''){
Var p = parms [I]. split ("= ");
If (p. length = 1 | (p. length = 2 & p [1] = '')){
Data. push (['']);
Index [p [0] = data. length-1;
} Else if (typeof (p [0]) = 'undefined' | p [0] = ''){
Data [0] = [p [1];
} Else if (typeof (index [p [0]) = 'undefined') {// c = aaa
Data. push ([p [1]);
Index [p [0] = data. length-1;
} Else {// c = aaa
Data [index [p [0]. push (p [1]);
}
}
}
}
})();
Return {
// Obtain parameters, similar to request. getParameter ()
Parm: function (o) {// o: parameter name or Parameter order
Try {
Return (typeof (o) = 'number '? Data [o] [0]: data [index [o] [0]);
} Catch (e ){
}
},
// Obtain the parameter group, similar to request. getParameterValues ()
ParmValues: function (o) {// o: parameter name or Parameter order
Try {
Return (typeof (o) = 'number '? Data [o]: data [index [o]);
} Catch (e ){}
},
// Whether the parmName parameter is included
HasParm: function (parmName ){
Return typeof (parmName) = 'string '? Typeof (index [parmName])! = 'Undefined': false;
},
// Obtain the parameter Map, similar to request. getParameterMap ()
ParmMap: function (){
Var map = {};
Try {
For (var p in index) {map [p] = data [index [p];}
} Catch (e ){}
Return map;
}
}
}();
// Example:
// Url: http: // 127.0.0.1/demo. jsp? A & page = 2 & B = dd & c = 123 & B = dd2
UrlParm. parm (0) // Result :"";
UrlParm. parm ('A') // Result :"";
UrlParm. parm ('page') // Result: "2 ";
UrlParm. parm (1) // Result: "2 ";
UrlParm. parm ("B") // Result: "dd ";
UrlParm. parmValues ("B") // result: ["dd", "dd2"];
UrlParm. hasParm ("B") // result: true;
UrlParm. hasParm ("x") // The result is false;
UrlParm. parmMap () // result: {a: [""], page: [2], B: ["dd", "dd2"], c: ["123"]};