Querystring processing class

Source: Internet
Author: User
/*
* For querystring (such? Userid = 222 & username = 23432sdf) Processing
*/
Function PageQuery (q ){
If (q. length> 1)
This. q = q. substring (1, q. length );
Else
This. q = null;
// Define a key-Value Pair
This. keyValuePairs = new Array ();
If (this. q ){
Var infos = this. q. split ("&");
For (var I = 0; I <infos. length; I ++ ){
// Add parameters to the array
This. keyValuePairs. push (infos [I]);
}
}
This. getKeyValuePairs = function () {return this. keyValuePairs };

// Obtain the number of current parameters
This. getLength = function () {return this. keyValuePairs. length };

// Find the corresponding value based on the input key
This. getValue = function (s ){
Var length = this. getLength ();
For (var I = 0; I <length; I ++ ){
If (this. keyValuePairs [I]. split ("=") [0] = s)
Return this. keyValuePairs [I]. split ("=") [1];
}
};

// Obtain all parameters
This. getParameters = function (){
Var parameters = new Array ();
Var length = this. getLength ();
For (var I = 0; I <length; I ++ ){
Parameters. push (this. keyValuePairs [I]. split ("=") [0]);
}
Return parameters;
}
}

Function analysisUrl (){
// Can be obtained using this. location. search? Parameters
// Alert (this. location. search );
Var page = new PageQuery ("? Userid = 234 & username = sdfsd ");
// Alert (page. getLength ());
Alert (page. getValue ("username "));
Var params = page. getParameters ();
For (var I = 0; I <params. length; I ++ ){
Alert (params [I]);
}
}
</Script>
The above example shows that this category is usable.

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.