Original: JS URL to pass the Chinese parameter garbled processing
The address shown in the browser is this:
But the address that was debugged by F12 changed:
This must be because the browser is encoding the URL path by default. The problem is that when we go to the value, we get a bunch of weird stuff back there. We don't get the value we want. What do we do? Here is only their own solution, perhaps not universal, share with you, there is a better way to sue me.
Get the value in the URL
functionrequest (paras) {varURL =Location.href; varparastring = url.substring (Url.indexof ("?") +1,url.length). Split ("&"); varParaobj = {}; for(vari=0; J=parastring[i]; i++) {paraobj[j.substring (0,j.indexof ("=")). toLowerCase ()] = j.substring (j.indexof ("=") +1, j.length); } varReturnValue =paraobj[paras.tolowercase ()]; if(typeof(returnvalue) = = "Undefined"){ return""; }Else{ returnreturnvalue; } } functionGethys () {if(Request (' Hys ')! = ") {
Decodeurl the Chinese and decoding the passing party
var hys=decodeuri (Request (' Hys ')); var select =document.getelementbyid (' Nybgs '); var selectvalue= ""; for (var i=0;i<select.options.length;i++) { Selectvalue=select.options[i].value; If(document.getElementById (' Nybgs '). options[i].value==hys) { document.getElementById (' Nybgs '). SelectedIndex = i; }}}
The request method is the method of taking the parameter in the address, and the decodeURI () method is to decode the Chinese of the passing party.
In Firefox and 360 and IE8 tested, no problem, do not know if you have any other better way?
JS URL to pass the Chinese parameter garbled processing