Home >Web Front-end >JS Tutorial >4 ways to share the parameter value (QueryString) in the URL using JS_javascript skills
Method 1: Regular method
alert(GetQueryString("Parameter name 2"));
alert(GetQueryString("Parameter name 3"));
Method 3: See also regular rules
Get url parameters through JS, this is often used. For example, for a URL: http://wwww.jb51.net/?q=js, if we want to get the value of parameter q, we can call it through the following function.
Method 4: Obtaining a single parameter
function GetRequest() {
var url = location.search; //Get the string after the "?" character in the url
if (url.indexOf("?") != -1) { //Determine whether there are parameters
var str = url.substr(1); //Start from the first character because the 0th one is the ? sign to get all strings except question marks
strs = str.split ("="); // Separate with an equal sign (because you know there is only one parameter, so use the equal sign to separate directly. If there are multiple parameters, use the & sign and then the equal sign to separate them)
alert(strs[ 1]); //Pop up the first parameter directly (if there are multiple parameters, it will be looped)
}
}