Hello everyone, I'm a little C,
We in the project development sometimes need to pass the value between the page and the page, then we may choose to pass the parameter in the Address bar, then the other page needs to get the parameters in the Address bar, today to share the address bar how to pass parameters and get Chinese parameters garbled solution. Please look at the code:
1 /**2 * Take the parameters of the address bar3 * 4 * @param key5 * Key is the parameter name passed for example Http://localhost/test/test.html?id=1&name= Zhang San, key is ID and name6 *7 * @returns8 */9 functionGeturlparam (key) {Ten //gets the parameter, taking a string with parameters, such as:? id=1&name= Zhang San One varURL =Window.location.search; A //Filter the Address bar with regular - varReg =NewRegExp ("(^|&)" + key + "= ([^&]*) (&|$)"); - //Match target Parameters the varresult = URL.SUBSTR (1). Match (reg); - //Return parameter Values - returnResult? decodeURIComponent (Result[2]):NULL; -}
Know the principle of the above code, it is very simple to use, when we need to get the address bar parameters, you can directly call the method Geturlparam (key) on it, and a good solution to the Chinese parameter garbled problem. You can try the results:
Geturlparam ("id") // result is 1geturlparam ("name") // result is Zhang San
There is a shortage of places, please advise.
JS get URL to pass the value and resolve get URL in the Chinese parameter garbled