Use js get parameters from the URL

Ideas:

  1, the URL acquired by the parameter string window.location.search

  2, then according to?, & Like character, resolution parameters into a string object json

  3, there is provided a method getParam acquired value corresponding to the key value according to the

 

Source as follows:

 
$ ( Function () {
 / * Create tool tools object and initializes * / 
    var oHttpLocalTool = HttpLocalToolInit (); 
    oHttpLocalTool.init (); 

    $ ( . '#InputPhoneNo') Val (oHttpLocalTool.getURLParam ( "PhoneNo" )); 
}); 

var HttpLocalToolInit = function () {
 / * when object initialization tool, to resolve the URL parameter string stored oHttpLocalToolobj.urlElments json object * / 
    var oHttpLocalToolobj = new new Object (); 

    oHttpLocalToolobj.init = function () { 
        oHttpLocalToolobj.searchString =  window.location.search;
        oHttpLocalToolobj.searchStringOHttpLocalToolobj.searchString.replace = (, ""? "" ); 
        OHttpLocalToolobj.urlElments = {};    / * create JSON object * / 

        var tmpArray = oHttpLocalToolobj.searchString.split ( "&");   / * use the split split string the array * / 
        for ( var I in tmpArray) {
             var Result = tmpArray [I] .split ( "=");   / * use dismantled again as the delimiter =   * / 
            oHttpLocalToolobj.urlElments [Result [ 0]] = result [. 1];   / * the result is loaded into the split JSON object   * / 
        } 
    }; 

    oHttpLocalToolobj.getURLParam = function (key) {
         return oHttpLocalToolobj.urlElments [key];     / * getURLParam method returns the value corresponding to key value * / 
    } 

    return oHttpLocalToolobj; 
};
 
Case online to obtain the URL parameters through the regular way, but is packaged in a direct approach. Each corresponding to a regular need to be resolved, feel more acquisition parameters affect efficiency ;

so after the preparation methods of these tools, also possible to package an object method, in order to reduce the performance overhead of repeated calculations.

Guess you like

Origin www.cnblogs.com/villWang/p/11314835.html