Rarely used the split method before, today to find some information.
How to use: Myarray=string.split ("|")
Description: "|" To cut the character character, string is the string to be cut, myarray is the result of the cut (stored in an array), and the method myarray[n],n=myarray.length is used.
At first I also use the thinking in the ASP to consider how to get the largest subscript myarray, certainly not UBound (myarray), looking for a half-day did not find, finally know, in fact, in the JavaScript array has a length property, Myarray.length-1 is also the myarray array of the largest subscript, very simple, it is easy to think, it is difficult to imagine.
Take a look at a split example: use JavaScript to get the address bar parameter.
Copy Code code as follows:
<script language= "JavaScript" >
<!--
function Request (strName)
{
var strhref = "Www.nextway.cn/index.htm?a=1&b=1&c=Split instance";
var intpos = Strhref.indexof ("?");
var strright = strhref.substr (intpos + 1);
var arrtmp = Strright.split ("&");
for (var i = 0; i < arrtmp.length; i++)
{
var arrtemp = arrtmp[i].split ("=");
if (arrtemp[0].touppercase () = = Strname.touppercase ()) return arrtemp[1];
}
Return "";
}
Alert (Request ("a"));
Alert (Request ("B"));
Alert (Request ("C"));
-->
</script>
There is another way to get the Address bar argument, regular expression:
Copy Code code as follows:
<script>
String.prototype.getQuery = function (name)
{
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = this.substr (This.indexof ("\?") +1). Match (REG);
if (r!=null) return unescape (r[2]); return null;
}
var str = "Www.nextway.cn/index.htm?a=1&b=1&c=Split instance";
Alert (Str.getquery ("a"));
Alert (Str.getquery ("B"));
Alert (Str.getquery ("C"));
</script>