Title Description
Get the parameters in the URL
1. Specify the parameter name, return the value of the parameter, or empty string
2. Do not specify the parameter name, return all parameter object or {}
3. If there are multiple parameters with the same name, the array is returned
1 functionGeturlparam (sURL, SKey) {2 varparam = Surl.split (' # ') [0].split ('? ') [1];3if(SKey) {//Specifying parameter names4varSTRs = Param.split (' & '));5varArrs =NewArray ();//returns an array if more than one parameter with the same name is present6 for(vari = 0, len = strs.length; i < Len; i++){7varTMP = strs[i].split (' = '));8if(Tmp[0] = =SKey) {9Arrs.push (tmp[1]);Ten } One } Aif(Arrs.length = = 1) {//returns the value of this parameter or an empty string - returnArrs[0]; -}Else if(Arrs.length = = 0){ thereturn""; -}Else { - returnArrs; - } +}Else{//does not specify a parameter name, returns all parameter objects, or {} -if(param = = Undefined | | param = = ""){ + return {}; A}Else { atvarSTRs = Param.split (' & ')); -varArrobj =NewObject (); - for(vari = 0, len = strs.length; i < Len; i++){ -varTMP = strs[i].split (' = ')); -if(! (Tmp[0]incharrobj)) { -Arrobj[tmp[0]] = []; in } -Arrobj[tmp[0]].push (tmp[1]); to } +returnarrobj; - } the } *}
Links: Https://www.nowcoder.com/questionTerminal/a3ded747e3884a3c86d09d88d1652e10
Source: Niu Ke Net
Get URL parameters