Obtaining Values from GET Parameters in JavaScript
Many web applications use GET parameters to pass data to the server. These parameters are appended to the URL in the format of key-value pairs, such as "?parameter1=value1¶meter2=value2". In JavaScript, there are built-in methods for accessing these parameters when working with the URL object.
In the given example, you need to retrieve the value associated with the 'c' parameter from the URL "www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5". Using the JavaScript URL object, you can achieve this as follows:
// Create a URL object with the specified URL string var url = new URL("www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5"); // Read the value associated with the 'c' parameter var cValue = url.searchParams.get("c"); // Print the value console.log(cValue);
The above is the detailed content of How to Extract GET Parameter Values Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!