Write a JavaScript function whose purpose is to receive the parameters of the GET request in the URL and return it as an object,
such as: var url = "Https://i.cnblogs.com/editposts.aspx?opt=1″."
This paper examines how JS obtains the URL as a string, as well as the method of string processing.
1. First think of the regular
2. Array methods
*-----------------Implement 1--------------------*/function getrequest () {var url = location.search;//Get URL in "?" Character string var therequest = new Object (); if (Url.indexof ("?") =-1) {var str = URL.SUBSTR (1); STRs = Str.split ("&"); for (var i = 0; i < strs.length; i + +) {Therequest[strs[i].split ("=") [0]]=unescape (Strs[i].split ("=") [1]);}} return therequest; }/*--------------------implementation 2 (Return $_get object, faux php mode)----------------------*/var $_get = (function () { var url = Window.document.location.href.toString (); var u = url.split ("?"); if (typeof (u[1]) = = "string") { u = u[1].split ("&"); var get = {}; for (Var i in u) { var j = u[i].split ("="); Get[j[0]] = j[1]; } return get; } else { return {};} }) (); /* 2nd way, when used, you can directly $_get[' get parameter ', directly get the value of the Get parameter */
JS written test-receive parameter for GET request