Copy Code code as follows:
var url = "http://127.0.0.1/e/action/ShowInfo.php?classid=9&id=2";//define Variable
function Parse_url (_url) {//Definition functions
var pattern =/(\w+) = (\w+)/ig;//define regular expression
var parames = {};//defined array
Url.replace (pattern, function (A, B, c) {parames[b] = c;});
/* This is the most critical. When replace is matched to classid=9. Then use the execution function (a,b,c), where a value is: Classid=9,b value is classid,c to 9; because in the definition The regular expression has a two-child match. The value of the array key is then assigned to 9, and then the ClassID is completed. Then continue to match to id=2, at which point the function (a,b,c) is executed, and the value of a is: Id=2,b is id,c with a value of 2, and the value of the array's key as the ID is assigned to 2.*/
Return parames;//returns this array.
}
var parames = parse_url (URL);
Alert (parames[' classid '] + "," + parames[' id '); print the corresponding value of the array according to the key value