Through JS to dynamically modify the URL, to achieve the URL of additions and deletions to check and change _javascript skills

Source: Internet
Author: User

Although the URL can be dynamically modified by submitting the post form in a get way, but if more than one button can be submitted in parallel, write a number of roughly the same, and some details of the difference between the form, it is inevitable that some improper, so think of the dynamic through JS to modify the URL, to achieve the URL additions and deletions to check the changes.

 <script> var lg= (function (LG) {var objurl=function (URL) {this.ourl=url| |
     Window.location.href;
   This.href= ""; the previous section This.params={};//url parameter Object this.jing= "";//#及后面部分 this.init (); }//Parse URL, get? Before saving this.href, parameter resolves to this.params object, #号及后面存入this. Jing objurl.prototype.init=function () {var str=this.o
     Url
     var index=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);
       var parts=str.split ("&");
         for (Var i=0;i<parts.length;i++) {var kv=parts[i].split ("=");
       THIS.PARAMS[KV[0]]=KV[1];
       }} else{This.href=this.ourl;
     this.params={};
   }//Only modifies This.params objurl.prototype.set=function (key,val) {this.params[key]=val;
}//Just set This.params objurl.prototype.remove=function (key) {     this.params[key]=undefined;
     The URL objurl.prototype.url=function () {var strurl=this.href after the three-part operation; var objps=[];//here is organized with arrays, then join operations for (var k in 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;
   return strurl;
   //Get parameter Value Objurl.prototype.get=function (key) {return this.params[key]; } LG.
   Url=objurl;
 return LG; } (Lg| |
 
     {})); var myurl=new LG.
     URL (WINDOW.LOCATION.HREF); Myurl.remove ("B"); Delete the B alert (Myurl.get ("a"));//Take the value of parameter A, here get 1 myurl.set ("a", 23);
 Modify the value of a to alert (Myurl.url ()); </script>

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.