Question: Write a JavaScript function parsequerystring, which is used to parse the URL parameter into an object.
Eg:var obj=parsequerystring (URL);
Create three types of objects:
One:
var person=new Object ();
Person.name= "Sun";
person.age=24;
Two:
var person=new Object ();
person["name"]= "Sun";
person["Age"]=24;
Three:
An object literal expression
var person={
Name: "Sun",
age:24
}
Ps:
1. In this example, it is more appropriate to use the second form to add elements to obj
2, Split ("&"), if the URL has only one parameter, there is no "&" time, also will not error, will return only array[0]
function parsequerystring (URL)
{
var obj={};
var keyvalue=[];
var key= "", value= "";
var parastring=url.substring (Url.indexof ("?") +1,url.length). Split ("&");
for (var i in parastring)
{
keyvalue=parastring[i].split ("=");
KEY=KEYVALUE[0];
VALUE=KEYVALUE[1];
Obj[key]=value;
}
return obj;
}