Do you know how to use Split in Javascript? I will give you a brief introduction here. I believe this article will surely help you gain some benefits.
How to use Split in Javascript
Usage: myArray = string. split ("| ")
Note: "|" indicates the feature character to be cut, string indicates the string to be cut, and myArray stores the cut result in an array. Use myArray [n], n = myArray. length.
At first, I used the thinking in asp to think about how to get the maximum subscript of myArray. It must not be Ubound (myArray). I did not find it for a long time, and finally I got it, in fact, arrays in Javascript have a length attribute, myArray. length-1 is the maximum subscript of the myArray array. It's easy to think about it.
Let's look at an example using split: use javascript to get the address bar parameters.
- <Scriptlanguagescriptlanguage = "JavaScript">
- <! --
- FunctionRequest (strName)
- {
- VarstrHref = "www.nextway.cn/index.htm? A = 1 & B = 1 & c = Split instance ";
- VarintPos = strHref. indexOf ("? ");
- VarstrRight = strHref. substr (intPos + 1 );
- VararrTmp = strRight. split ("&");
- For (vari = 0; I <arrTmp. length; I ++)
- {
- VararrTemp = arrTmp [I]. split ("= ");
- If (arrTemp [0]. toUpperCase () = strName. toUpperCase ())
- ReturnarrTemp [1];
- }
- Return "";
- }
- Alert (Request (""));
- Alert (Request ("B "));
- Alert (Request ("c "));
- // -->
- </Script>
-
There is another way to obtain the address bar parameters, the regular expression:
- <Script>
- String. prototype. getQuery = function (name)
- {
- Varreg = newRegExp ("(^ | &)" + name + "= ([^ &] *) (& | $ )");
- Varr = this. substr (this. indexOf ("? ") + 1). match (reg );
- If (r! = Null) returnunescape (r [2]); returnnull;
- }
- Varstr = "www.nextway.cn/index.htm? A = 1 & B = 1 & c = Split instance ";
- Alert (str. getQuery (""));
- Alert (str. getQuery ("B "));
- Alert (str. getQuery ("c "));
- </Script>
-