var url = "http://www.xxx.com/index.aspx?classid=9&id=2";
To get the tail parameters
Define variables
function parse_url(_url){
//Define function
var pattern = /(w )=( w )/ig;//Define regular expression
var parames = {};//Define array
url.replace(pattern, function(a, b, c){
parames[b] = c;
});
/*This is the most critical. When replace matches classid=9, then execute function(a,b,c); where the value of a is: classid=9 , the value of b is classid, and the value of c is 9; (This is a back reference. Because there are two submatches when defining the regular expression.) Then assign the value of the array key to classid to 9; and then complete. Continue matching until id=2; at this time, execute function (a, b, c); where the value of a is: id=2, the value of b is id, and the value of c is 2; then the key of the array is id The value is assigned to 2. */
return parames;//Return this array.
}
var parames = parse_url(url);
alert(parames['classid'] ", " parames[ 'id']);//Finally print. Print the value corresponding to the array according to the key value
var url = "http://attit.ppk365.com/084200001682"
var reg = /http:// (. )/(w )/ig;
url.replace(reg, function(a,b,c){
alert(a); //Get http://attit.ppk365.com/084200001682
alert(b); //Get attit.ppk365.com
alert(c); //Get 084200001682
});