JavaScript gets the number of references in the current page URL can use the search method of location, get to the URL? The latter part, like 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, obtained id=1 after interception, the value of the ID must be obtained, can be split using the split () method, and the split expression is "=". See the detailed example below:
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");}};
Assume that there are multiple parameters in the URL. That is, we use & to cut in each of the parameters, and then we get it? The subsequent string can be split with split first. Splits the expression to &, and then gets the array in which each string is cut. You can get each of the parameters.
JavaScript gets the number of references in the current URL