① A student wrote this on the Internet:
Function QueryString (key ){
Var paras = location. search;
If (paras ){
Var arr = paras. substr (1). split ("&"), data;
For (I in arr ){
Data = arr [I]. split ("= ");
If (data [0] = key ){
Return data [1]
}
}
}
} Veryhuo.com
② This was originally collected and modified: liehuo.net
I added a decodeURIComponent method.If you add or not, I add
// If you use a page parameter with Chinese characters to jump to the page,
// The URL is similar to this (http: // xxxx/MyJsp. jsp? Id = 3 & name = haha ):
// Travel 3 converts Chinese characters to http: // xxxx/MyJsp. jsp? Id = 3 & name = % BA % C7 % BA % C7
// In IE, http: // xxxx/MyJsp. jsp by default? Id = 3 & name = haha
Function Request (name ){
Var pattern =/(\ w *) = ([a-zA-Z0-9 \ u4e00-\ u9fa5] +)/ig, params = {}; // define a regular expression and an empty object
DecodeURIComponent (window. location. href, true). replace (pattern, function (a, B, c) {params [B] = c ;});
Return params [name]? Params [name]: null;
}
// Method for Evaluating the. Net Indexer
Function Params (){
Var pattern =/(\ w *) = ([a-zA-Z0-9 \ u4e00-\ u9fa5] +)/ig, params = {}; // define a regular expression and an empty object
DecodeURIComponent (window. location. href, true). replace (pattern, function (a, B, c) {params [B] = c ;});
Return params;
}
Var params = Params ();
Alert (params ["name"]);
// Of course, liehuo.net
// Alert (params. name); fire net