Method 1:
The following is an implementation method of distinct Cr into pT. This function obtains parameters through the delimiter in window. Location. href.
With this function, you can pass parameters between pages.
/*
* Function: obtain parameters from href.
* Shref: http://www.artfh.com/arg.htm? Arg1 = D & arg2 = Re
* Sargname: arg1, arg2
* Return: the value of Arg. D, re
*/
Function getargsfromhref (shref, sargname)
{
VaR ARGs = shref. Split ("? ");
VaR retval = "";
If (ARGs [0] = shref)/* the parameter is blank */
{
Return retval;/* No processing required */
}
VaR STR = ARGs [1];
ARGs = Str. Split ("&");
For (VAR I = 0; I <args. length; I ++)
{
STR = ARGs [I];
VaR Arg = Str. Split ("= ");
If (Arg. Length <= 1) continue;
If (ARG [0] = sargname) retval = Arg [1];
}
Return retval;
}
Method 2:
Parameters are passed in HTML addresses for other tasks.
<SCR platinum Pt>
/* Purpose: Set the parameter id = 1 in the direct receiving column to the value of ID */
Urlinfo = Window. Location. href; // obtain the URL of the current page
Len = urlinfo. length; // obtain the URL length.
Offset = urlinfo. indexof ("? "); // Set the start position of the parameter string
Newsidinfo = urlinfo. substr (offset, Len) // retrieve the parameter string and obtain a string similar to "id = 1 ".
Newsids = newsidinfo. Split ("="); // splits the obtained parameter string by "="
Newsid = newsids [1]; // obtain the parameter value.
Newsname = newsids [0]; // obtain the parameter name.
</Scr platinum Pt>
Method 3:
<Script language = "JavaScript">
Function getvalue (name ){
VaR STR = Window. Location. Search; // location. Search is from the current URL? A string starting with a sign, for example, a http://www.51job.com/viewthread.jsp? Tid = 22720 what is its search?
Tid = 22720
If (Str. indexof (name )! =-1 ){
VaR pos_start = Str. indexof (name) + name. Length + 1;
VaR pos_end = Str. indexof ("&", pos_start );
If (pos_end =-1 ){
Alert (Str. substring (pos_start ));
} Else {
Alert ("sorry, this value does not exist! ");
}
}
</SCRIPT>
Method 4:
When performing a Sino-English conversion, you must obtain and retrieve the parameters accurately. Therefore, you have made a simple HTML file and used JavaScript to obtain an object in the address bar.
There are three methods:
1. Request. querystring ("parameter") // obtain the specified parameter and return a string;
2. Request. querystrings (); // obtain all parameters and return an array;
3. Request. setquery ("parameter", "parameter value"); // if this parameter exists in the current address bar, this parameter is updated; otherwise, a new address bar parameter string is returned.
For example:
The parameter string in the current address bar is :? Name = A & Site = never_online
Alert (request. setquery ("name", "bluedestiny "))
If "name" is included in the address bar parameter? Name = bluedestiny & Site = never_online
The setquery method can automatically append parameters. For example:
The parameter string in the current address bar is :? Site = never_online
Alert (request. setquery ("name", "bluedestiny "))
? Site = never_online & name = bluedestiny
Similarly, if there is no parameter in the address bar, it will automatically append the parameter.
Alert (request. setquery ("name", "bluedestiny "))
? Name = bluedestiny
<Script language = "JavaScript">
<! --
// Author: Never-Online
// Web: never-online.net
VaR request = {
Querystring: function (VAL ){
VaR uri = Window. Location. search;
VaR Re = new Regexp ("" + Val + "\ = ([^ \ &?] *) "," Ig ");
Return (URI. Match (re ))? (URI. Match (re) [0]. substr (Val. Length + 1): NULL );
},
Querystrings: function (){
VaR uri = Window. Location. search;
VaR Re =/\ W * \ = ([^ \ & \?] *)/Ig;
VaR retval = [];
While (ARR = re.exe C (URI ))! = NULL)
Retval. Push (ARR [0]);
Return retval;
},
Setquery: function (val1, val2 ){
VaR A = This. querystrings ();
VaR retval = "";
VaR seted = false;
VaR Re = new Regexp ("^" + val1 + "\ = ([^ \ &?] *) $ "," Ig ");
For (VAR I = 0; I <A. length; I ++ ){
If (Re. Test (A [I]) {
Seted = true;
A [I] = val1 + "=" + val2;
}
}
Retval = A. Join ("&");
Return "? "+ Retval + (seted? "": (Retval? "&": "") + Val1 + "=" + val2 );
}
}
Alert (request. setquery ("e", "B "))
// -->
</SCRIPT>