I visited the websites of many foreign book publishers on Sunday! I found that SAMs has a good practical idea for Label display! In general, JavaScript is used to dynamically change the display and hiding of Div. Let's take a look at the js code written by others:
- <SCRIPT type = "text/JavaScript">
- // <! [CDATA [
- // The tag array. If it is written to me, I cannot think of it as saving it.
- VaR tabarray = new array ();
- // Which label is displayed by default
- Function showdefaulttab (){
- // Show 'description' tab by default, else show first
- If (! Showtab ('item1 ')){
- Displaytoggle (tabarray [0] + "_ container", true, 'iner iner on ');
- Document. getelementbyid (tabarray [0]). classname = 'selected ';
- }
- }
- // Change the hidden display of the content box and redraw the display style: It feels a bit like the Adaptive Mode
- Function showtab (Tabid ){
- VaR found = false;
- For (VAR I = 0; I <tabarray. length; I ++ ){
- If (tabarray [I]! = Tabid ){
- Displaytoggle (tabarray [I] + "_ container", false, 'Container ');
- Document. getelementbyid (tabarray [I]). classname = '';
- } Else {
- Displaytoggle (tabarray [I] + "_ container", true, 'iner iner on ');
- Document. getelementbyid (tabarray [I]). classname = 'selected ';
- Found = true;
- }
- }
- Return found;
- }
- // The showtab function calls this function to hide the content box.
- Function displaytoggle (ID, show, newclass ){
- VaR OBJ = Document. getelementbyid (ID );
- If (OBJ! = NULL ){
- If (show ){
- OBJ. style. Visibility = "visible ";
- OBJ. style. Display = "Block ";
- } Else {
- OBJ. style. Visibility = "hidden ";
- OBJ. style. Display = "NONE ";
- }
- If (newclass! = NULL)
- OBJ. classname = newclass;
- }
- }
- //]>
- </SCRIPT>
Let's look at the HTML code! I believe everyone guessed the following:
- <Div id = "sitepage">
- <Div id = "productbss" class = "tabwidget">
- <Ul class = "tabs">
- <Li id = "Item1">
- <A id = "info3" href = "# info3" onclick = "showtab ('item1'); Return false;"> description </a>
- </LI>
- <Script language = "JavaScript">
- Tabarray. Push ('item1 ');
- </SCRIPT>
- <Li id = "item2">
- <A id = "info8" href = "# info8" onclick = "showtab ('item2'); Return false;"> sample content </a>
- </LI>
- <Script language = "JavaScript">
- Tabarray. Push ('item2 ');
- </SCRIPT>
- </Ul>
- </Div>
- <Div id = "bsscontent">
- <Div id = "item1_container">
- <! -- Detail content -->
- </Div>
- <Div id = "item2_container">
- <! -- Detail content -->
- </Div>
- </Div>
- <Script language = "JavaScript">
Showdefaulttab ();
</SCRIPT>
- </Div>
Finally, the CSS style definition:
- <Style type = "text/CSS">
- <! --
- Body {margin: 150px 0 0 0; font-size: 0.8em; font-family: "lucida Grande", Arial, Helvetica, sans-serif ;}
- Div # sitepage {margin: 0 0 0 184px; padding: 0; width: 400px; Height: auto ;}
- Div # productbss {clear: Both ;}
- Div # bsscontent {margin:-1px 0 0 0; padding: 1em; border-Right: 1px solid # c7c8ca; border-left: 1px solid # c7c8ca; border-bottom: 1px solid # c7c8ca; border-top: 1px solid # c7c8ca ;}
- /*-Tab widget (blog sidebar )-*/
- Div. tabwidget {border-left: 1px solid # c7c8ca; position: relative ;}
- /* Tab control */
- Div. tabwidget ul. Tabs {list-style: none; margin: 0; padding: 0 0 1px 0; Height: 2em; border-bottom: 1px solid # c7c8ca ;}
- Div. tabwidget ul. tabs Li {display: block; float: Left; Background-color: # Eee; Border: 1px solid # c7c8ca; border-width: 1px 1px 1px 0; padding: 0 1em; line-Height: 2em; margin: 0 ;}
- Div. tabwidget ul. Tabs Li. Selected {background-color: # FFF; border-bottom: 1px solid # FFF ;}
- /* Layer Control */
- Div. tabwidget Div. Container {display: none; clear: Both; Border: 1px solid # c7c8ca; border-width: 0 1px 1px 0; position: relative ;}
- Div. tabwidget Div. On {display: block ;}
- /* Content control */
- : Link,: visited {text-Decoration: none ;}
- A: link {color: # 004f7f ;}
- A: visited {color: #2e87b2 ;}
- A: hover, A: active {color: # 004f7f; text-Decoration: underline ;}
- -->
- </Style>
The best thing to learn is: the application of JavaScript arrays in this process! Someone will say! Hard coding is not better! At least one function and two push operations are missing. This form is dead! But it is necessary to use people's thinking about writing code flexibly! If you only want to learn the superficial form of people, there's nothing to say!