This article examples for everyone to analyze the JavaScript implementation tab tab switch debugging notes, for your reference, the specific contents are as follows
When you make a navigation bar, clicking on the navigation bar element produces a corresponding change, and the element displays a special style.
JS Source code:
Navigation bar Click Transform Content
function Tabswitch (_this,num) {
var tag = document.getElementById ("nav9");
var number = Tag.getelementsbytagname ("a"); Gets the number of navigation bar elements (getElementsByTagName is the return element group)
var divnum = document.getelementsbyclassname ("Eachdiv"); Gets the number of div for the navigation element for
(var i=0;i<number.length;i++) {//number is an array, which should display its length of 5
number[i with Number.length]. ClassName = ""; Clears the special style for all navigation bar elements
Divnum[i].style.display = "none";//All other div is hidden
}
_this.classname = "L_nav1_no1"; Add a style to the current navigation bar element
var content = document.getElementById ("l_no2_" +num);//The Div content.style.display for the current navigation bar element
"Block"; Displays the div section for the current navigation bar element
}
HTML code:
Effect Chart:
Debug Notes:
1. Error One:
var number = Tag.getelementsbytagname ("a"). Length;
(1) Error:
(2) Interpretation and correction:
**getelementsbytagname () is to return to the element group, if you take its length, number is just a figure, so number[i].classname = ""; **
Correct:
var number = Tag.getelementsbytagname ("a");
2. Error Two:
for (Var i=0;i<number;i++) {
number[i].classname = ""; Clears the special style for all navigation bar elements
Divnum[i].style.display = "none";//All other div is hidden
}
The number here should be a digit, representing the number of a elements, the length of which is obtained by the error, which should read:
for (Var i=0;i<number.length;i++) {//number is an array
number[i].classname = ""; Clears the special style for all navigation bar elements
Divnum[i].style.display = "none";//All other div is hidden
}
The above is the entire content of this article, I hope to help you learn.