JavaScript gets the parameters in the current page URL can use the search method of location, get to the URL? The following sections, such as Http:localhost:8080/manager/index.jsp?id=1
Use the search method of location to get to the string? id=1; want to get? The following key-value pairs can be intercepted using the substring method, get id=1 after interception, obtain the value of the ID, you can split it using the Split () method, and split the expression to "=". Here's a look at the specific example:
Window.onload = function () {var param = location.search.substring (1); var results = param.split ("="); var result = Results[1 ];if (result== "-1") {alert ("id value is-1");} else if (result = = "1") {alert ("id value is 1");} else if (result = = "2") {alert ("ID value is 2");}};
If there are multiple parameters in the URL, that is, each parameter uses & to split, then we get to? The subsequent string can be split with split first, split the expression to &, and then get the array to split each string. To get each parameter.
JavaScript gets the parameters in the current URL