JS Native URL operation function, perfect.
/*****************************//*Dynamically modifying URLs*//*****************************/varLg= (function(LG) {varObjurl=function(URL) { This. ourl=url| |window.location.href; This. href= "";//? previous section This. params={};//URL Parameter Object This. jing= "";//#及后面部分 This. Init (); } //parse the URL, get the this.href, the parameter resolves to the This.params object, #号及后面存入this. Jingobjurl.prototype.init=function(){ varStr= This. Ourl; varIndex=str.indexof ("#"); if(index>0){ This. jing=str.substr (index); STR=str.substring (0, index); } Index=str.indexof ("?")); if(index>0){ This. href=str.substring (0, index); STR=str.substr (index+1); varParts=str.split ("&"); for(vari=0;i<parts.length;i++){ varKv=parts[i].split ("="); This. params[kv[0]]=kv[1]; } } Else{ This. href= This. Ourl; This. params={}; } } //just modify This.params .objurl.prototype.set=function(key,val) { This. params[key]=Val; } //just set This.paramsObjurl.prototype.remove=function(key) { This. params[key]=undefined; } //URL based on three-part operationObjurl.prototype.url=function(){ varStrurl= This. href; varObjps=[];//Here we use arrays to organize and join operations. for(varKinch This. Params) { if( This. Params[k]) {Objps.push (k+"="+ This. Params[k]); } } if(objps.length>0) {strURL+="?" +objps.join ("&"); } if( This. jing.length>0) {strURL+= This. Jing; } returnstrURL; } //Get parameter valuesobjurl.prototype.get=function(key) {return This. Params[key]; } LG. URL=Objurl; returnLG;} (LG|| {}));
Apply the URL action function above, get the URL and its parameters, and decode the Chinese in Rul with the jquery self-contained function before use.
Finally, the assignment is done.
$ (document). Ready (function(){ varMyurl=NewLG. URL (WINDOW.LOCATION.HREF); //gets the URL parameter, decodes the value into the Select, implements the Select anti-refresh$ ("#yewu"). Val (decodeURIComponent (Myurl.get ("Yewu")))); $("#fuwu"). Val (decodeURIComponent (Myurl.get ("Fuwu")))); $("#leixing"). Val (decodeURIComponent (Myurl.get ("leixing")))); $('. Casesel '). Change (function(){ varp1=$ (' #yewu '). Val ();//the value of the Yewu varp2=$ (' #fuwu '). Val ();//the value of the Fuwu varp3=$ (' #leixing '). Val ();//the value of the leixingwindow.location.href= "/case/?yewu=" +p1+ "&fuwu=" +p2+ "&leixing=" +P3;//page jumps and passes the parameter });});
JS Native URL operation function, and the use of the method. (Attached: below and jquery to the URL of the Chinese decoding function)