JS Show or hide a layer function

Source: Internet
Author: User
Tags array array length split variable

/*
========================
Function: Show or hide layers
Showdiv (divid_array,showlocality_array)
parameter description:
Divid_ Array all the layer IDs to be manipulated, separated by commas
Showlocality_array the position of all the layers to be displayed in the parameter Dividarray. All is displayed for "0" or empty, and all is hidden if it is set to a negative number.
For example: Showdiv (' div3,div1,div2 ', ' 2,3 ') to display the second (DIV1) and third layer (DIV2), the first layer (DIV3) will be hidden.
========================
*/
Function Showdiv (divid_array,showlocality_array)
{
 var div_ Array = new Array ();
 var Locality_array = new Array ();
 var intlocality;//showlocality_array Array length
 var intdiv;//div_array array length
 var intTemp = 1;// Temporary variable
 var inttmp = 1;//temporary variable
 
 //initialization
 if (divid_array)
 {
   Div_array = Divid_array.split (",");
 }else{
  intdiv = 0;
&NBSP}
 if (showlocality_array)
 {
  locality_array = Showlocality_array.split (",") ;
  intlocality = locality_array.length;

for (var n = 0;n < intlocality;n++)
{
IntTemp *= Locality_array[n];

}
if (intTemp <= 0)
{
intlocality = intTemp;
}else{
intlocality = Div_array.length;

while (intlocality > 0)
{
Intlocality-= 1;
document.getElementById ("" + div_array[intlocality] + ""). Style.display = "None";
}
intlocality = 1;
}
}else{
intlocality = 0;
}

Show specified layer
if (intdiv!= 0 && intlocality >0)
{
Intdiv = Div_array.length;
intlocality = Locality_array.length;

Sort Locality_array Array
for (var n = 0;n < intlocality;n++)
{
IntTemp = Locality_array[n];

for (var m = n + 1;m < intlocality;m++)
{
if (Locality_array[n] > Locality_array[m])
{
Locality_array[n] = locality_array[m];
LOCALITY_ARRAY[M] = intTemp;
IntTemp = Locality_array[n];
}
}
}

intlocality = Locality_array.length;
intTemp = 0;

//
while (IntTemp < intlocality)
{
if ((Locality_array[inttemp]-1) < div_array.length)
{
Inttmp = locality_array[inttemp]-1;
document.getElementById ("" + div_array[inttmp] + ""). Style.display = "block";
}

IntTemp + 1;
}
}
else if (intlocality = 0)
{//Show all layers
intlocality = Div_array.length;

while (intlocality > 0)
{
Intlocality-= 1;
document.getElementById ("" + div_array[intlocality] + ""). Style.display = "block";
}
}else{//Hide All Layers
intlocality = Div_array.length;

while (intlocality > 0)
{
Intlocality-= 1;
document.getElementById ("" + div_array[intlocality] + ""). Style.display = "None";
}
}
}



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.