JS Native URL operation function, and the use of the method. (Attached: below and jquery to the URL of the Chinese decoding function)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.